ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2026-01-19 09:21:43
Exec Total Coverage
Lines: 3084 8756 35.2%
Functions: 86 314 27.4%
Branches: 2673 7903 33.8%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/pal_tables.h"
10 #include "base/version.h"
11 #include "base/zapp.h"
12 #include "base/zdefs.h"
13 #include "dialog/info.h"
14 #include "gui/jwin.h"
15 #include "metadata/metadata.h"
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/packfile.h"
20 #include "base/cpool.h"
21 #include "base/autocombo.h"
22 #include "base/gui.h"
23 #include "base/msgstr.h"
24 #include "zc/zelda.h"
25 #include "zq/zq_class.h"
26 #include "zq/render.h"
27 #include "zq/render_map_view.h"
28 #include "zq/zq_misc.h"
29 #include "zq/zquest.h"
30 #include "base/qst.h"
31 #include "base/colors.h"
32 #include "tiles.h"
33 #include "base/zsys.h"
34 #include "sprite.h"
35 #include "items.h"
36 #include "zc/zc_sys.h"
37 #include "base/md5.h"
38 #include "hero_tiles.h"
39 #include "subscr.h"
40 #include "zq/zq_strings.h"
41 #include "zq/zq_subscr.h"
42 #include "zc/ffscript.h"
43 #include "base/util.h"
44 #include "zq/zq_files.h"
45 #include "slopes.h"
46 #include "drawing.h"
47 #include "zinfo.h"
48 #include "zq/render_minimap.h"
49 #include "base/mapscr.h"
50 #include "iter.h"
51 #include <fmt/format.h>
52 #include <filesystem>
53 #include "advanced_music.h"
54
55 #ifdef __EMSCRIPTEN__
56 #include "base/emscripten_utils.h"
57 #endif
58
59 namespace fs = std::filesystem;
60
61 using namespace util;
62
63 extern uint8_t ViewLayer3BG, ViewLayer2BG;
64 extern int32_t LayerDitherBG, LayerDitherSz;
65 extern bool NoHighlightLayer0;
66
67 using std::string;
68 using std::pair;
69
70 #define COLOR_SOLID vc(4)
71 #define COLOR_SLOPE vc(13)
72 #define COLOR_LADDER vc(6)
73 //#define COLOR_EFFECT vc(10)
74
75 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
76 extern char msgbuf[MSG_NEW_SIZE*8];
77
78 extern string zScript;
79
80 12 zmap Map;
81 int32_t prv_mode=0;
82
83 bool save_warn=true;
84
85 int32_t COMBOPOS(int32_t x, int32_t y)
86 {
87 return (((y) & 0xF0) + ((x) >> 4));
88 }
89 int32_t COMBOPOS_B(int32_t x, int32_t y)
90 {
91 if(unsigned(x) >= 256 || unsigned(y) >= 176)
92 return -1;
93 return COMBOPOS(x,y);
94 }
95 int32_t COMBOX(int32_t pos)
96 {
97 return ((pos) % 16 * 16);
98 }
99 int32_t COMBOY(int32_t pos)
100 {
101 return ((pos) & 0xF0);
102 }
103
104 void reset_dmap(int32_t index)
105 {
106 bound(index,0,MAXDMAPS-1);
107 DMaps[index].clear();
108 DMaps[index].title = "";
109 sprintf(DMaps[index].intro, " ");
110 }
111
112 void reset_dmaps()
113 {
114 for(int32_t i=0; i<MAXDMAPS; i++)
115 reset_dmap(i);
116 }
117
118 void truncate_dmap_title(std::string& title)
119 {
120 title.resize(21, ' ');
121 }
122
123 mapscr* zmap::get_prvscr()
124 {
125 return &prvscr;
126 }
127
128
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
138 zmap::zmap()
129 {
130 23 can_paste=false;
131 23 prv_cmbcycle=0;
132 23 prv_advance=0;
133 23 prv_freeze=0;
134 23 copyffc=-1;
135
136 23 memset(scrpos, 0, sizeof(scrpos));
137 23 memset(scrview, 0, sizeof(scrview));
138 23 screens=NULL;
139 23 prv_time=0;
140 23 prv_scr=0;
141 23 prv_map=0;
142 23 copyscr=0;
143 23 cursor={};
144 copymap=0;
145 layer_target_map = 0;
146 layer_target_scr = 0;
147 layer_target_multiple = 0;
148 }
149
150 11 void zmap::clear()
151 {
152
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
153 11 }
154 void zmap::force_refr_pointer()
155 {
156 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
157 screens = nullptr;
158 else screens = &TheMaps[cursor.map*MAPSCRS];
159 }
160 bool zmap::CanUndo()
161 {
162 return input_undo_stack.size() > 0;
163 }
164 bool zmap::CanRedo()
165 {
166 return input_redo_stack.size() > 0;
167 }
168 bool zmap::CanPaste()
169 {
170 return can_paste;
171 }
172 int32_t zmap::CopyScr()
173 {
174 return (copymap<<8)+copyscr;
175 }
176 int32_t zmap::getCopyFFC()
177 {
178 return copyffc;
179 }
180 set_ffc_command::data_t zmap::getCopyFFCData()
181 {
182 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
183 }
184 67 int32_t zmap::getMapCount()
185 {
186 67 return map_count;
187 }
188 int32_t zmap::getLayerTargetMap()
189 {
190 return layer_target_map;
191 }
192 int32_t zmap::getLayerTargetScr()
193 {
194 return layer_target_scr;
195 }
196 int32_t zmap::getLayerTargetMultiple()
197 {
198 return layer_target_multiple;
199 }
200 bool zmap::isDungeon(int32_t scr)
201 {
202 for(int32_t i=0; i<4; i++)
203 {
204 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
205 {
206 return false;
207 }
208 }
209
210 return true;
211 }
212
213 bool zmap::clearall(bool validate)
214 {
215 Color=0;
216 char tbuf[10];
217
218 if((header.templatepath[0]!=0)&&validate)
219 {
220 if(!valid_zqt(header.templatepath))
221 {
222 displayinfo("Error","Invalid Quest Template");
223 return false;
224 }
225 }
226
227 for(int32_t i=0; i<map_count; i++)
228 {
229 setCurrMap(i);
230 sprintf(tbuf, "%d", i);
231 clearmap(true);
232 }
233
234 setCurrMap(0);
235 return true;
236 }
237
238 bool zmap::reset_templates(bool validate)
239 {
240 //why are we doing this?
241 if(colordata==NULL)
242 {
243 return false;
244 }
245
246 //int32_t ret;
247 word version, build, dummy, sversion=0;
248 byte dummyc;
249 word dummyw;
250 //int32_t section_size;
251 word temp_map_count;
252 mapscr temp_mapscr;
253 PACKFILE *f=NULL;
254
255 // setPackfilePassword(datapwd);
256 f=open_quest_template(&header, "modules/classic/default.qst", validate);
257 get_version_and_build(f, &version, &build);
258
259 if(!find_section(f, ID_MAPS))
260 {
261 // setPackfilePassword(NULL);
262 return false;
263 }
264
265 //section version info
266 if(!p_igetw(&sversion,f))
267 {
268 return false;
269 }
270
271 if(!p_igetw(&dummy,f))
272 {
273 return false;
274 }
275
276 //section size
277 dword dummy_size;
278 if(!p_igetl(&dummy_size,f))
279 {
280 return false;
281 }
282
283 //finally... section data
284 if(!p_igetw(&temp_map_count,f))
285 {
286 return false;
287 }
288
289 if(version>12)
290 {
291 if(!p_getc(&dummyc,f))
292 return qe_invalid;
293
294 if(!p_getc(&dummyc,f))
295 return qe_invalid;
296
297 if(!p_igetw(&dummyw,f))
298 return qe_invalid;
299
300 if(!p_igetw(&dummyw,f))
301 return qe_invalid;
302
303 if(!p_igetw(&dummyw,f))
304 return qe_invalid;
305
306 if(!p_igetw(&dummyw,f))
307 return qe_invalid;
308
309 if(!p_igetw(&dummyw,f))
310 return qe_invalid;
311
312 if(!p_igetw(&dummyw,f))
313 return qe_invalid;
314
315 if(!p_igetw(&dummyw,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_getc(&dummyc,f))
328 return qe_invalid;
329
330 if(!p_getc(&dummyc,f))
331 return qe_invalid;
332 }
333
334 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
335 {
336 readmapscreen(f, &header, &temp_mapscr, sversion);
337 }
338
339 readmapscreen(f, &header, &TheMaps[128], sversion);
340 readmapscreen(f, &header, &TheMaps[129], sversion);
341
342 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
343 {
344 readmapscreen(f, &header, &temp_mapscr, sversion);
345 }
346
347 if(version>12)
348 {
349 if(!p_getc(&dummyc,f))
350 return qe_invalid;
351
352 if(!p_getc(&dummyc,f))
353 return qe_invalid;
354
355 if(!p_igetw(&dummyw,f))
356 return qe_invalid;
357
358 if(!p_igetw(&dummyw,f))
359 return qe_invalid;
360
361 if(!p_igetw(&dummyw,f))
362 return qe_invalid;
363
364 if(!p_igetw(&dummyw,f))
365 return qe_invalid;
366
367 if(!p_igetw(&dummyw,f))
368 return qe_invalid;
369
370 if(!p_igetw(&dummyw,f))
371 return qe_invalid;
372
373 if(!p_igetw(&dummyw,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_getc(&dummyc,f))
386 return qe_invalid;
387
388 if(!p_getc(&dummyc,f))
389 return qe_invalid;
390 }
391
392 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
393 {
394 readmapscreen(f, &header, &temp_mapscr, sversion);
395 }
396
397 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
398 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
399
400 pack_fclose(f);
401 clear_quest_tmpfile();
402
403 return true;
404 }
405
406 bool zmap::clearmap(bool newquest)
407 {
408 if(cursor.map<map_count)
409 {
410 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
411 {
412 clearscr(i);
413 }
414
415 setCurrScr(0);
416
417 if(newquest)
418 {
419 if(!reset_templates(false))
420 {
421 displayinfo("Error","Error resetting template screens.");
422 }
423 }
424 }
425
426 return true;
427 }
428
429 MapCursor zmap::getCursor() const
430 {
431 return cursor;
432 }
433
434 11 void zmap::setCursor(MapCursor new_cursor)
435 {
436
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (cursor == new_cursor && screens)
437 return;
438
439
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (screens)
440 pushCursorToHistory(std::move(cursor));
441 11 cursor = std::move(new_cursor);
442
443
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
444 11 screens = &TheMaps[cursor.map*MAPSCRS];
445
446 11 refresh_color();
447 11 setlayertarget();
448 11 reset_combo_animations2();
449 11 mmap_mark_dirty();
450 11 regions_mark_dirty();
451 11 }
452
453 void zmap::pushCursorToHistory(MapCursor cursor)
454 {
455 if (cursor_history_enabled)
456 {
457 cursor_undo_stack.push_back(std::move(cursor));
458 cursor_redo_stack = {};
459 CapCursorHistory();
460 }
461 }
462
463 bool zmap::isValidPosition(ComboPosition pos) const
464 {
465 return pos.is_valid(cursor);
466 }
467
468 int zmap::getScreenForPosition(ComboPosition pos) const
469 {
470 return cursor.viewscr + pos.screen_offset();
471 }
472
473 mapscr* zmap::CurrScr()
474 {
475 return screens+cursor.screen;
476 }
477 mapscr* zmap::Scr(int32_t scr)
478 {
479 return screens+scr;
480 }
481 mapscr* zmap::Scr(ComboPosition pos)
482 {
483 if (!pos.is_valid(cursor))
484 return nullptr;
485
486 int screen_offset = pos.screen_offset();
487 int screen = cursor.viewscr + screen_offset;
488 return AbsoluteScr(cursor.map, screen);
489 }
490 mapscr* zmap::Scr(ComboPosition pos, int layer)
491 {
492 int map = cursor.map;
493 int screen = cursor.viewscr + pos.screen_offset();
494 if (layer)
495 {
496 mapscr* scr = Map.AbsoluteScr(map, screen);
497 map = scr->layermap[CurrentLayer-1]-1;
498 screen = scr->layerscreen[CurrentLayer-1];
499 }
500
501 return AbsoluteScr(map, screen);
502 }
503 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
504 {
505 mapscr* scr = Scr(pos, layer);
506 if (scr && !(scr->valid&mVALID))
507 {
508 scr->valid |= mVALID;
509 setcolor(Color, scr);
510 }
511 return scr;
512 }
513 mapscr* zmap::AbsoluteScr(int32_t scr)
514 {
515 if(unsigned(scr) >= MAPSCRS*getMapCount())
516 return nullptr;
517 return &TheMaps[scr];
518 }
519 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
520 {
521 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
522 return nullptr;
523 return AbsoluteScr((map*MAPSCRS)+scr);
524 }
525 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
526 {
527 mapscr* scr = AbsoluteScr(map, screen);
528 if (scr && !(scr->valid&mVALID))
529 {
530 scr->valid |= mVALID;
531 setcolor(Color, scr);
532 }
533 return scr;
534 }
535 void zmap::set_prvscr(int32_t map, int32_t scr)
536 {
537 prvscr = *get_canonical_scr(map, scr);
538
539 for(int32_t i=0; i<6; i++)
540 {
541 if(prvscr.layermap[i]>0)
542 {
543 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
544 }
545 else
546 prvlayers[i].valid = 0;
547 }
548
549 prv_map=map;
550 prv_scr=scr;
551 }
552 92 int32_t zmap::getCurrMap()
553 {
554 92 return cursor.map;
555 }
556 11 void zmap::regions_mark_dirty()
557 {
558 11 regions_dirty = true;
559 11 }
560 void zmap::regions_refresh()
561 {
562 if (!regions_dirty)
563 return;
564
565 regions_dirty = false;
566 region_descriptions.clear();
567
568 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
569 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
570 region_descriptions.clear();
571 }
572 const std::vector<region_description>& zmap::get_region_descriptions()
573 {
574 regions_refresh();
575 return region_descriptions;
576 }
577 bool zmap::is_region(int screen)
578 {
579 if (screen < 0 || screen >= 128)
580 return false;
581
582 regions_refresh();
583 return current_map_region_ids[screen];
584 }
585 bool zmap::isDark(int scr)
586 {
587 return (screens[scr].flags&fDARK)!=0;
588 }
589 bool zmap::isValid(int32_t scr)
590 {
591 return (screens[scr].valid&mVALID)!=0;
592 }
593 bool zmap::isValid(int32_t map, int32_t scr)
594 {
595 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
596 }
597
598 void zmap::setCurrMap(int32_t index)
599 {
600 scrpos[cursor.map] = cursor.screen;
601 scrview[cursor.map] = cursor.viewscr;
602
603 auto new_cursor = cursor;
604 new_cursor.map = bound(index,0,map_count);
605
606 new_cursor.viewscr = scrview[new_cursor.map];
607 new_cursor.setScreen(scrpos[new_cursor.map]);
608 setCursor(std::move(new_cursor));
609 }
610
611 20 int32_t zmap::getCurrScr()
612 {
613 20 return cursor.screen;
614 }
615 void zmap::setCurrScr(int32_t scr)
616 {
617 if (scr == cursor.screen)
618 return;
619
620 auto new_cursor = cursor;
621 new_cursor.setScreen(scr);
622 setCursor(std::move(new_cursor));
623 }
624
625 int32_t zmap::getViewScr()
626 {
627 return cursor.viewscr;
628 }
629
630 void zmap::setViewSize(int32_t size)
631 {
632 auto new_cursor = cursor;
633 new_cursor.setSize(size);
634 setCursor(std::move(new_cursor));
635 }
636
637 1 int32_t zmap::getViewSize()
638 {
639 1 return cursor.size;
640 }
641
642 11 void zmap::setlayertarget()
643 {
644 11 layer_target_map = 0;
645 11 layer_target_multiple = 0;
646
647
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
648 {
649
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
650 {
651 7616 int32_t i=(m*MAPSCRS+s);
652 7616 mapscr *ts=&TheMaps[i];
653
654 // Search through each layer
655
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
656 {
657
3/4
✓ Branch 0 taken 15868 times.
✓ Branch 1 taken 29828 times.
✓ Branch 2 taken 15868 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
658 {
659 if(layer_target_map > 0)
660 {
661 layer_target_multiple += 1;
662 continue;
663 }
664
665 layer_target_map = m+1;
666 layer_target_scr = s;
667 }
668 45696 }
669 7616 }
670 56 }
671 11 }
672
673 11 void zmap::refresh_color()
674 {
675 11 auto color = getcolor();
676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (Color != color)
677 {
678 11 loadlvlpal(color);
679 11 rebuild_trans_table();
680 11 }
681 11 }
682
683 void zmap::setcolor(int color, mapscr* scr)
684 {
685 if (!scr)
686 scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 refresh_color();
691
692 mmap_mark_dirty();
693 }
694
695 11 int32_t zmap::getcolor()
696 {
697 11 return getcolor(cursor.screen);
698 }
699
700 11 int32_t zmap::getcolor(int screen)
701 {
702
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 mapscr& scr = prv_mode ? prvscr : screens[screen];
703
704
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (scr.valid & mVALID)
705 11 return scr.color;
706
707 return map_infos[cursor.map].autopalette;
708 11 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 auto const& mapinf = map_infos[cursor.map];
829 for(int q = 0; q < 6; ++q)
830 {
831 auto layer = mapinf.autolayers[q];
832 screens[scr].layermap[q] = layer;
833 screens[scr].layerscreen[q] = layer ? scr : 0;
834 }
835 screens[scr].color = mapinf.autopalette;
836 if (scr == cursor.screen)
837 refresh_color();
838 mmap_mark_dirty();
839 }
840
841 const char *loaderror[] =
842 {
843
844 "OK","File not found","Incomplete data",
845 "Invalid version","Invalid file"
846
847 };
848
849 int32_t zmap::load(const char *path)
850 {
851 PACKFILE *f=pack_fopen_password(path,F_READ, "");
852
853 if(!f)
854 return 1;
855
856
857 int16_t version;
858 byte build;
859
860 //get the version
861 if(!p_igetw(&version,f))
862 {
863 goto file_error;
864 }
865
866 //get the build
867 if(!p_getc(&build,f))
868 {
869 goto file_error;
870 }
871
872 for(int32_t i=0; i<MAPSCRS; i++)
873 {
874 mapscr tmpimportscr;
875 tmpimportscr.zero_memory();
876 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
877 {
878 al_trace("failed zmap::load\n");
879 goto file_error;
880 }
881
882 switch(ImportMapBias)
883 {
884 case 0:
885 *(screens+i) = tmpimportscr;
886 break;
887
888 case 1:
889 if(!(screens[i].valid&mVALID))
890 {
891 *(screens+i) = tmpimportscr;
892 }
893 break;
894
895 case 2:
896 if(tmpimportscr.valid&mVALID)
897 {
898 *(screens+i) = tmpimportscr;
899 }
900 break;
901 }
902 }
903
904
905 pack_fclose(f);
906
907 setCurrScr(0);
908 mmap_mark_dirty();
909 regions_mark_dirty();
910 return 0;
911
912 file_error:
913 pack_fclose(f);
914 clearmap(false);
915 return 2;
916 }
917
918 int32_t zmap::save(const char *path)
919 {
920 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
921
922 if(!f)
923 return 1;
924
925 if(!p_iputw(V_MAPS,f))
926 {
927 pack_fclose(f);
928 return 3;
929 }
930
931 // This was the "build number", but that's totally useless here. Keep this junk byte
932 // so as not to totally break exports between ZC versions.
933 if(!p_putc(0,f))
934 {
935 pack_fclose(f);
936 return 3;
937 }
938
939 for(int32_t i=0; i<MAPSCRS; i++)
940 {
941 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
942 {
943 pack_fclose(f);
944 return 2;
945 }
946 }
947
948 pack_fclose(f);
949 return 0;
950 }
951
952
953 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
954 {
955 // Hookshots can be blocked by solid combos on all 3 ground layers.
956 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
957
958 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
959 return true;
960 if (c->walk&(1<<i))
961 return false;
962
963 for(int32_t k=0; k<2; k++)
964 {
965 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
966
967 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
968 {
969 return false;
970 }
971 }
972
973 return true;
974 }
975
976 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
977 {
978 // Hookshots can be blocked by solid combos on all 3 ground layers.
979 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
980
981 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
982 return true;
983 if (c->walk&(1<<i))
984 return false;
985
986 for(int32_t k=0; k<2; k++)
987 {
988 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
989
990 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
991 {
992 return false;
993 }
994 }
995
996 return true;
997 }
998
999 bool zmap::isstepable(int32_t combo)
1000 {
1001 // This is kind of odd but it's true to the engine (see maps.cpp)
1002 return (combo_class_buf[combobuf[combo].type].ladder_pass);
1003 }
1004
1005 // Returns the letter of the warp combo.
1006 int32_t zmap::warpindex(int32_t combo)
1007 {
1008 switch(combobuf[combo].type)
1009 {
1010 case cCAVE:
1011 case cPIT:
1012 case cSTAIR:
1013 case cCAVE2:
1014 case cSWIMWARP:
1015 case cDIVEWARP:
1016 case cSWARPA:
1017 return 0;
1018
1019 case cCAVEB:
1020 case cPITB:
1021 case cSTAIRB:
1022 case cCAVE2B:
1023 case cSWIMWARPB:
1024 case cDIVEWARPB:
1025 case cSWARPB:
1026 return 1;
1027
1028 case cCAVEC:
1029 case cPITC:
1030 case cSTAIRC:
1031 case cCAVE2C:
1032 case cSWIMWARPC:
1033 case cDIVEWARPC:
1034 case cSWARPC:
1035 return 2;
1036
1037 case cCAVED:
1038 case cPITD:
1039 case cSTAIRD:
1040 case cCAVE2D:
1041 case cSWIMWARPD:
1042 case cDIVEWARPD:
1043 case cSWARPD:
1044 return 3;
1045
1046 case cPITR:
1047 case cSTAIRR:
1048 case cSWARPR:
1049 return 4;
1050 }
1051
1052 return -1;
1053
1054 }
1055
1056 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1057 {
1058 if(top)
1059 line(dest,x,y,x+15,y,c);
1060 rectfill(dest,x,y,x+3,y+15,c);
1061 rectfill(dest,x+12,y,x+15,y+15,c);
1062 rectfill(dest,x+4,y+2,x+11,y+5,c);
1063 rectfill(dest,x+4,y+10,x+11,y+13,c);
1064 }
1065
1066 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1067 {
1068 line(dest,x,y,x+15,y,c);
1069 }
1070
1071 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1072 {
1073 int32_t cx = COMBOX(pos);
1074 int32_t cy = COMBOY(pos);
1075
1076 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1077
1078 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1079
1080 int32_t bridgedetected = 0;
1081
1082 for(int32_t i=0; i<4; i++)
1083 {
1084 int32_t tx=((i&2)<<2)+x;
1085 int32_t ty=((i&1)<<3)+y;
1086 int32_t tx2=((i&2)<<2)+cx;
1087 int32_t ty2=((i&1)<<3)+cy;
1088 for (int32_t m = layer; m <= 1; m++)
1089 {
1090 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1091 {
1092 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1093 {
1094 bridgedetected |= (1<<i);
1095 }
1096 }
1097 else
1098 {
1099 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1100 {
1101 bridgedetected |= (1<<i);
1102 }
1103 }
1104 }
1105 if (bridgedetected & (1<<i))
1106 {
1107 if (i >= 3) break;
1108 else continue;
1109 }
1110 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1111 {
1112 for(int32_t k=0; k<8; k+=2)
1113 for(int32_t j=0; j<8; j+=2)
1114 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1115 }
1116 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1117 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1118
1119 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1120 {
1121 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1122 {
1123 for(int32_t k=0; k<8; k+=2)
1124 for(int32_t j=0; j<8; j+=2)
1125 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1126 }
1127 else
1128 {
1129 int32_t color = COLOR_SOLID;
1130
1131 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1132 color=vc(6);
1133 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1134 color=vc(7);
1135
1136 rectfill(dest,tx,ty,tx+7,ty+7,color);
1137 }
1138 }
1139 }
1140
1141 bridgedetected = 0;
1142 for(int32_t i=0; i<4; i++)
1143 {
1144 int32_t tx2=((i&2)<<2)+cx;
1145 int32_t ty2=((i&1)<<3)+cy;
1146 for (int32_t m = 0; m <= 1; m++)
1147 {
1148 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1149 {
1150 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1151 {
1152 bridgedetected |= (1<<i);
1153 }
1154 }
1155 else
1156 {
1157 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1158 {
1159 bridgedetected |= (1<<i);
1160 }
1161 }
1162 }
1163 }
1164
1165 // Draw damage combos
1166 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1167 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1168 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1169 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1170 || combo_class_buf[c1.type].modify_hp_amount
1171 || combo_class_buf[c2.type].modify_hp_amount;
1172
1173 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1174
1175 if(dmg)
1176 {
1177 if (bridgedetected <= 0)
1178 {
1179 for(int32_t k=0; k<16; k+=2)
1180 for(int32_t j=0; j<16; j+=2)
1181 if(((k+j)/2)%2)
1182 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1183 }
1184 else
1185 {
1186 for(int32_t i=0; i<4; i++)
1187 {
1188 if (!(bridgedetected & (1<<i)))
1189 {
1190 int32_t tx=((i&2)<<2)+x;
1191 int32_t ty=((i&1)<<3)+y;
1192 for(int32_t k=0; k<8; k+=2)
1193 for(int32_t j=0; j<8; j+=2)
1194 if(((k+j)/2)%2)
1195 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1196 }
1197 }
1198 }
1199 }
1200
1201 if(c.type == cSLOPE)
1202 {
1203 slope_info s(c, x, y);
1204 s.draw(dest, 0, 0, COLOR_SLOPE);
1205 }
1206 auto fl0 = MAPFLAG2(-1,cx,cy);
1207 auto fl1 = MAPFLAG2(0,cx,cy);
1208 auto fl2 = MAPFLAG2(1,cx,cy);
1209 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1210 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1211 {
1212 bool top = false;
1213 if(cy)
1214 {
1215 top = true;
1216 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1217 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1218 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1219 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1220 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1221 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1222 {
1223 top = false;
1224 }
1225 }
1226 draw_ladder(dest,x,y,COLOR_LADDER,top);
1227 }
1228 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1229 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1230 {
1231 draw_platform(dest,x,y,COLOR_LADDER);
1232 }
1233 }
1234
1235 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1236 {
1237 int32_t cx = COMBOX(pos);
1238 int32_t cy = COMBOY(pos);
1239
1240 if (screen < 0) return;
1241 if (map < 0) return;
1242
1243 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1244
1245 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1246
1247 int32_t bridgedetected = 0;
1248 for(int32_t i=0; i<4; i++)
1249 {
1250 int32_t tx=((i&2)<<2)+x;
1251 int32_t ty=((i&1)<<3)+y;
1252 int32_t tx2=((i&2)<<2)+cx;
1253 int32_t ty2=((i&1)<<3)+cy;
1254 for (int32_t m = layer; m <= 1; m++)
1255 {
1256 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1257 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1258 {
1259 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1260 {
1261 bridgedetected |= (1<<i);
1262 }
1263 }
1264 else
1265 {
1266 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1267 {
1268 bridgedetected |= (1<<i);
1269 }
1270 }
1271 }
1272 if (bridgedetected & (1<<i))
1273 {
1274 continue;
1275 }
1276 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1277 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1278
1279
1280 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1281 {
1282 for(int32_t k=0; k<8; k+=2)
1283 for(int32_t j=0; j<8; j+=2)
1284 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1285 }
1286 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1287 {
1288 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1289 {
1290 for(int32_t k=0; k<8; k+=2)
1291 for(int32_t j=0; j<8; j+=2)
1292 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1293 }
1294 else
1295 {
1296 int32_t color = COLOR_SOLID;
1297
1298 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1299 color=vc(6);
1300 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1301 color=vc(7);
1302
1303 rectfill(dest,tx,ty,tx+7,ty+7,color);
1304 }
1305 }
1306 }
1307
1308 bridgedetected = 0;
1309 for(int32_t i=0; i<4; i++)
1310 {
1311 int32_t tx2=((i&2)<<2)+cx;
1312 int32_t ty2=((i&1)<<3)+cy;
1313 for (int32_t m = 0; m <= 1; m++)
1314 {
1315 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1316 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1317 {
1318 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1319 {
1320 bridgedetected |= (1<<i);
1321 }
1322 }
1323 else
1324 {
1325 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1326 {
1327 bridgedetected |= (1<<i);
1328 }
1329 }
1330 }
1331 }
1332
1333 // Draw damage combos
1334 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1335 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1336 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1337 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1338 || combo_class_buf[c1.type].modify_hp_amount
1339 || combo_class_buf[c2.type].modify_hp_amount;
1340
1341 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1342
1343 if(dmg)
1344 {
1345 if (bridgedetected <= 0)
1346 {
1347 for(int32_t k=0; k<16; k+=2)
1348 for(int32_t j=0; j<16; j+=2)
1349 if(((k+j)/2)%2)
1350 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1351 }
1352 else
1353 {
1354 for(int32_t i=0; i<4; i++)
1355 {
1356 if (!(bridgedetected & (1<<i)))
1357 {
1358 int32_t tx=((i&2)<<2)+x;
1359 int32_t ty=((i&1)<<3)+y;
1360 for(int32_t k=0; k<8; k+=2)
1361 for(int32_t j=0; j<8; j+=2)
1362 if(((k+j)/2)%2)
1363 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1364 }
1365 }
1366 }
1367 }
1368
1369 if(c.type == cSLOPE)
1370 {
1371 slope_info s(c, x, y);
1372 s.draw(dest, 0, 0, COLOR_SLOPE);
1373 }
1374 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1375 auto fl1 = MAPFLAG3(map,screen,0,pos);
1376 auto fl2 = MAPFLAG3(map,screen,1,pos);
1377 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1378 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1379 {
1380 bool top = false;
1381 if(cy)
1382 {
1383 top = true;
1384 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1385 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1386 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1387 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1388 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1389 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1390 {
1391 top = false;
1392 }
1393 }
1394 draw_ladder(dest,x,y,COLOR_LADDER,top);
1395 }
1396 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1397 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1398 {
1399 draw_platform(dest,x,y,COLOR_LADDER);
1400 }
1401 }
1402
1403 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1404 {
1405 const newcombo& c = combobuf[cmbdat];
1406
1407 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1408
1409 for(int32_t i=0; i<4; i++)
1410 {
1411 int32_t tx=((i&2)<<2)+x;
1412 int32_t ty=((i&1)<<3)+y;
1413
1414 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1415 {
1416 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 else
1421 {
1422 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1423 }
1424 }
1425
1426
1427 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1428 {
1429 for(int32_t k=0; k<8; k+=2)
1430 for(int32_t j=0; j<8; j+=2)
1431 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1432 }
1433 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1434 {
1435 if(c.type==cLADDERHOOKSHOT)
1436 {
1437 for(int32_t k=0; k<8; k+=2)
1438 for(int32_t j=0; j<8; j+=2)
1439 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1440 }
1441 else
1442 {
1443 int32_t color = COLOR_SOLID;
1444
1445 if(c.type==cLADDERONLY)
1446 color=vc(6);
1447 else if(c.type==cHOOKSHOTONLY)
1448 color=vc(7);
1449
1450 rectfill(dest,tx,ty,tx+7,ty+7,color);
1451 }
1452 }
1453
1454 // Draw damage combos
1455 if(combo_class_buf[c.type].modify_hp_amount != 0)
1456 {
1457 for(int32_t k=0; k<8; k+=2)
1458 for(int32_t j=0; j<8; j+=2)
1459 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1460 }
1461 }
1462
1463 if(c.type == cSLOPE)
1464 {
1465 slope_info s(c, 0, 0);
1466 zfix const& slope = s.slope();
1467
1468 BITMAP* sub = create_bitmap_ex(8,16,16);
1469 clear_bitmap(sub);
1470 s.draw(sub, 0, 0, COLOR_SLOPE);
1471 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1472 destroy_bitmap(sub);
1473 }
1474 if(c.flag == mfSIDEVIEWLADDER)
1475 {
1476 draw_ladder(dest,x,y,COLOR_LADDER);
1477 }
1478 else if(c.flag == mfSIDEVIEWPLATFORM)
1479 {
1480 draw_platform(dest,x,y,COLOR_LADDER);
1481 }
1482 }
1483
1484 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1485 {
1486 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1487 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1488 }
1489 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1490 {
1491 newcombo const& c = combobuf[cmbdat];
1492
1493 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1494 {
1495 if(sflag)
1496 {
1497 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1498 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1499 }
1500
1501 if(c.flag)
1502 {
1503 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1504 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1505 }
1506 }
1507
1508 if(flags&cCSET)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1512 }
1513 else if(flags&cCTYPE)
1514 {
1515 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1516 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1517 }
1518 }
1519
1520 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1521 {
1522 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1523
1524 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1525 if(repos)
1526 {
1527 combotile_override_x = x+(8*(scale-1));
1528 combotile_override_y = y+(8*(scale-1));
1529 }
1530 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1531 if(repos) combotile_override_x = combotile_override_y = -1;
1532 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1533 destroy_bitmap(b);
1534 }
1535 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1536 {
1537 static newcombo nilcombo;
1538 nilcombo.tile = 0;
1539
1540 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1541
1542 if(c.tile==0)
1543 {
1544 rectfill(dest,x,y,x+15,y+15,vc(0));
1545 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1546 return;
1547 }
1548
1549 putcombo(dest,x,y,cmbdat,cset);
1550
1551 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1552 {
1553 if(sflag)
1554 {
1555 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1556 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1557 }
1558
1559 if(combobuf[cmbdat].flag)
1560 {
1561 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1562 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1563 }
1564 }
1565
1566 if(flags&cWALK)
1567 {
1568 put_walkflags(dest,x,y,cmbdat,0);
1569 }
1570
1571 if(flags&cCSET)
1572 {
1573 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1574 // text_mode(inv?vc(15):vc(0));
1575 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1576 }
1577 else if(flags&cCTYPE)
1578 {
1579 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1580 // text_mode(inv?vc(15):vc(0));
1581 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1582 }
1583 }
1584 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1585 {
1586 auto blitx = 1 + (slot % 16) * 17;
1587 auto blity = 1 + (slot / 16) * 17;
1588 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1589 }
1590
1591
1592 void copy_mapscr(mapscr *dest, const mapscr *src)
1593 {
1594 if(!dest || !src) return;
1595 *dest = *src;
1596 }
1597
1598 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1599 {
1600 int32_t x=0,y=0;
1601 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1602
1603 switch(side)
1604 {
1605 case up:
1606 case down:
1607 x=((pos&15)<<4)+xofs;
1608 y=(ignorepos?0:(pos&0xF0))+yofs;
1609 break;
1610
1611 case left:
1612 case right:
1613 x=(ignorepos?0:((pos&15)<<4))+xofs;
1614 y=(pos&0xF0)+yofs;
1615 break;
1616 }
1617
1618 switch(type)
1619 {
1620 case dt_lock:
1621 case dt_shut:
1622 case dt_boss:
1623 case dt_bomb:
1624 switch(side)
1625 {
1626 case up:
1627 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1628 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1629 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1630 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1631 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1633 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1635 break;
1636
1637 case down:
1638 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1639 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1640 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1641 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1642 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1644 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1646 break;
1647
1648 case left:
1649 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1650 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1651 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1653 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1655
1656 if(x+16 >= dest->w)
1657 break;
1658
1659 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1660 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1661 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1663 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1665 break;
1666
1667 case right:
1668
1669 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1670 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1671 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1673 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1675
1676 if(x+16 <= 0)
1677 break;
1678
1679 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1680 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1681 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1682 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1683 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1684 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1685 break;
1686 }
1687
1688 break;
1689
1690 case dt_pass:
1691 case dt_wall:
1692 case dt_walk:
1693 default:
1694 break;
1695 }
1696 }
1697
1698 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1699 {
1700 int32_t x=((pos&15)<<4)+xofs;
1701 int32_t y=(pos&0xF0)+yofs;
1702 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1703
1704
1705 switch(side)
1706 {
1707 case up:
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1709 {
1710 overcombo(dest,x,y,
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1713 }
1714
1715 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1716 {
1717 overcombo(dest,x+16,y,
1718 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1719
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1721 }
1722
1723 break;
1724
1725 case down:
1726 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1727 {
1728 overcombo(dest,x,y,
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1730 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1731 }
1732
1733 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1734 {
1735 overcombo(dest,x+16,y,
1736 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1737 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1738 }
1739
1740 break;
1741
1742 case left:
1743 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1744 {
1745 overcombo(dest,x,y,
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1747 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1748 }
1749
1750 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1751 {
1752 overcombo(dest,x,y+16,
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1754 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1755 }
1756
1757 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1758 {
1759 overcombo(dest,x,y+32,
1760 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1761 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1762 }
1763
1764 break;
1765
1766 case right:
1767 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1768 {
1769 overcombo(dest,x,y,
1770 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1772 }
1773
1774 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1775 {
1776 overcombo(dest,x,y+16,
1777
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1779 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1780 }
1781
1782 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1783 {
1784 overcombo(dest,x,y+32,
1785 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1786 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1787 }
1788
1789 break;
1790 }
1791 }
1792
1793 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1794 {
1795 word cmbcheck1, cmbcheck2;
1796 newcombo combocheck1, combocheck2;
1797 combocheck1 = combobuf[0];
1798 combocheck2 = combobuf[0];
1799 combocheck1.walk = 0;
1800 combocheck2.walk = 0;
1801
1802 int32_t layermap, layerscreen;
1803
1804 switch(dir)
1805 {
1806 case up:
1807 {
1808 if(i>15) //not top row of combos
1809 {
1810 return false;
1811 }
1812
1813 if(screen<16) //top row of screens
1814 {
1815 return false;
1816
1817 }
1818
1819 //check main screen
1820 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1821 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1822 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1823 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1824
1825 //check layer 1
1826 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1827
1828 if(layermap>-1 && layermap<map_count)
1829 {
1830 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1831 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1832 if (combobuf[cmbcheck1].type == cBRIDGE)
1833 {
1834 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1835 {
1836 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1837 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1838 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1839 }
1840 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1841 }
1842 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1843 }
1844
1845 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1846
1847 if(layermap>-1 && layermap<map_count)
1848 {
1849 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1850 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1851 if (combobuf[cmbcheck2].type == cBRIDGE)
1852 {
1853 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1854 {
1855 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1856 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1857 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1858 }
1859 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1860 }
1861 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1862 }
1863
1864 //check layer 2
1865 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1866
1867 if(layermap>-1 && layermap<map_count)
1868 {
1869 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1870
1871 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1872 if (combobuf[cmbcheck2].type == cBRIDGE)
1873 {
1874 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1875 {
1876 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1877 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1878 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1879 }
1880 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1881 }
1882 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1883 }
1884
1885 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1886
1887 if(layermap>-1 && layermap<map_count)
1888 {
1889 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1890 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1891 if (combobuf[cmbcheck2].type == cBRIDGE)
1892 {
1893 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1894 {
1895 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1896 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1897 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1898 }
1899 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1900 }
1901 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1902 }
1903
1904 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1905 {
1906 return true;
1907 }
1908
1909 break;
1910 }
1911 case down:
1912 {
1913 if(i<160) //not bottom row of combos
1914 {
1915 return false;
1916 }
1917
1918 if(screen>111) //bottom row of screens
1919 {
1920 return false;
1921 }
1922
1923 //check main screen
1924 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1925 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1926 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1927 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1928
1929
1930 //check layer 1
1931 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1932
1933 if(layermap>-1 && layermap<map_count)
1934 {
1935 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1936 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1937 if (combobuf[cmbcheck1].type == cBRIDGE)
1938 {
1939 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1940 {
1941 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1942 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1943 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1944 }
1945 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1946 }
1947 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1948 }
1949
1950 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1951
1952 if(layermap>-1 && layermap<map_count)
1953 {
1954 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1955 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1956 if (combobuf[cmbcheck2].type == cBRIDGE)
1957 {
1958 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1959 {
1960 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1961 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1962 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1963 }
1964 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1965 }
1966 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1967 }
1968
1969 //check layer 2
1970 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1971
1972 if(layermap>-1 && layermap<map_count)
1973 {
1974 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1975 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1976 if (combobuf[cmbcheck1].type == cBRIDGE)
1977 {
1978 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1979 {
1980 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1981 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1982 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1983 }
1984 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1985 }
1986 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1987 }
1988
1989 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1990
1991 if(layermap>-1 && layermap<map_count)
1992 {
1993 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1994 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1995 if (combobuf[cmbcheck2].type == cBRIDGE)
1996 {
1997 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1998 {
1999 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2000 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2001 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2002 }
2003 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2004 }
2005 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2006 }
2007
2008 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2009 {
2010 return true;
2011 }
2012
2013 break;
2014 }
2015 case left:
2016 {
2017 if((i&0xF)!=0) //not left column of combos
2018 {
2019 return false;
2020 }
2021
2022 if((screen&0xF)==0) //left column of screens
2023 {
2024 return false;
2025 }
2026
2027 //check main screen
2028 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2029 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2030 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2031 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2032
2033 //check layer 1
2034 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2035
2036 if(layermap>-1 && layermap<map_count)
2037 {
2038 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2039 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2040 if (combobuf[cmbcheck1].type == cBRIDGE)
2041 {
2042 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2043 {
2044 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2045 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2046 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2047 }
2048 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2049 }
2050 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2051 }
2052
2053 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2054
2055 if(layermap>-1 && layermap<map_count)
2056 {
2057 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2058 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2059 if (combobuf[cmbcheck2].type == cBRIDGE)
2060 {
2061 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2062 {
2063 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2064 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2065 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2066 }
2067 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2068 }
2069 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2070 }
2071
2072 //check layer 2
2073 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2074
2075 if(layermap>-1 && layermap<map_count)
2076 {
2077 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2078 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2079 if (combobuf[cmbcheck1].type == cBRIDGE)
2080 {
2081 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2082 {
2083 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2084 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2085 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2086 }
2087 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2088 }
2089 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2090 }
2091
2092 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2093
2094 if(layermap>-1 && layermap<map_count)
2095 {
2096 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2097 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2098 if (combobuf[cmbcheck2].type == cBRIDGE)
2099 {
2100 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2101 {
2102 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2103 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2104 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2105 }
2106 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2107 }
2108 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2109 }
2110
2111 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2112 {
2113 return true;
2114 }
2115
2116 break;
2117 }
2118 case right:
2119 {
2120 if((i&0xF)!=15) //not right column of combos
2121 {
2122 return false;
2123 }
2124
2125 if((screen&0xF)==15) //right column of screens
2126 {
2127 return false;
2128 }
2129
2130 //check main screen
2131 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2132 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2133 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2134 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2135
2136 //check layer 1
2137 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2138
2139 if(layermap>-1 && layermap<map_count)
2140 {
2141 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2142 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2143 if (combobuf[cmbcheck1].type == cBRIDGE)
2144 {
2145 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2146 {
2147 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2148 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2149 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2150 }
2151 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2152 }
2153 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2154 }
2155
2156 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2157
2158 if(layermap>-1 && layermap<map_count)
2159 {
2160 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2161 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2162 if (combobuf[cmbcheck2].type == cBRIDGE)
2163 {
2164 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2165 {
2166 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2167 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2168 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2169 }
2170 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2171 }
2172 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2173 }
2174
2175 //check layer 2
2176 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2177
2178 if(layermap>-1 && layermap<map_count)
2179 {
2180 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2181 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2182 if (combobuf[cmbcheck1].type == cBRIDGE)
2183 {
2184 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2185 {
2186 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2187 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2188 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2189 }
2190 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2191 }
2192 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2193 }
2194
2195 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2196
2197 if(layermap>-1 && layermap<map_count)
2198 {
2199 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2200
2201 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2202 if (combobuf[cmbcheck2].type == cBRIDGE)
2203 {
2204 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2205 {
2206 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2207 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2208 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2209 }
2210 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2211 }
2212 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2213 }
2214
2215 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2216 {
2217 return true;
2218 }
2219
2220 break;
2221 }
2222 }
2223
2224 return false;
2225 }
2226
2227 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2228 {
2229 int32_t checkcombo;
2230
2231 if(alignment_arrow_timer>31)
2232 {
2233 if(scr<0)
2234 {
2235 scr=cursor.screen;
2236 }
2237
2238 if((scr<128)) //do the misalignment arrows
2239 {
2240 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2241 {
2242 if(misaligned(cursor.map, scr, checkcombo, up))
2243 {
2244 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 }
2246 }
2247
2248 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2249 {
2250 if(misaligned(cursor.map, scr, checkcombo, down))
2251 {
2252 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 }
2254 }
2255
2256 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2257 {
2258 if(misaligned(cursor.map, scr, checkcombo, left))
2259 {
2260 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2261 }
2262 }
2263
2264 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2265 {
2266 if(misaligned(cursor.map, scr, checkcombo, right))
2267 {
2268 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2269 }
2270 }
2271
2272 int32_t tempalign;
2273
2274 //check top left corner
2275 checkcombo=0;
2276 tempalign=0;
2277 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2278 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2279
2280 switch(tempalign)
2281 {
2282 case 0:
2283 break;
2284
2285 case 1: //up
2286 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2287 break;
2288
2289 case 2: //left
2290 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2291 break;
2292
2293 case 3: //up-left
2294 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2295 break;
2296 }
2297
2298 //check top right corner
2299 checkcombo=15;
2300 tempalign=0;
2301 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2302 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2303
2304 switch(tempalign)
2305 {
2306 case 0:
2307 break;
2308
2309 case 1: //up
2310 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2311 break;
2312
2313 case 2: //right
2314 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2315 break;
2316
2317 case 3: //up-right
2318 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2319 break;
2320 }
2321
2322 //check bottom left corner
2323 checkcombo=160;
2324 tempalign=0;
2325 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2326 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2327
2328 switch(tempalign)
2329 {
2330 case 0:
2331 break;
2332
2333 case 1: //down
2334 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2335 break;
2336
2337 case 2: //left
2338 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2339 break;
2340
2341 case 3: //down-left
2342 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2343 break;
2344 }
2345
2346 //check bottom right corner
2347
2348 checkcombo=175;
2349 tempalign=0;
2350 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2351 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2352
2353 switch(tempalign)
2354 {
2355 case 0:
2356 break;
2357
2358 case 1: //down
2359 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2360 break;
2361
2362 case 2: //right
2363 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2364 break;
2365
2366 case 3: //down-right
2367 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2368 break;
2369 }
2370 }
2371 }
2372 }
2373
2374 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2375 {
2376 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2377 }
2378
2379 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2380 {
2381 if (map < 0 || screen < 0) return 0;
2382
2383 if(pos>175 || pos < 0)
2384 return 0;
2385
2386 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2387
2388 if (!m->is_valid()) return 0;
2389
2390 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2391
2392 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2393
2394 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2395
2396 if (!scr->is_valid()) return 0;
2397
2398 return scr->data[pos]; // entire combo code
2399 }
2400
2401 // Takes array index layer num., not actual layer num.
2402 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2403 {
2404 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2405
2406 if(map<0)
2407 map=cursor.map;
2408
2409 if(scr<0)
2410 scr=cursor.screen;
2411
2412 mapscr *screen1;
2413
2414 if(prv_mode)
2415 {
2416 screen1=get_prvscr();
2417 }
2418 else
2419 {
2420 screen1=AbsoluteScr(cursor.map,cursor.screen);
2421 }
2422
2423 int32_t layermap;
2424 layermap=screen1->layermap[lyr]-1;
2425
2426 if(layermap<0 || layermap >= map_count) return 0;
2427
2428 mapscr *layer;
2429
2430 if(prv_mode)
2431 layer = &prvlayers[lyr];
2432 else
2433 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2434
2435 int32_t pos = COMBOPOS(x,y);
2436
2437 if(pos>175 || pos < 0)
2438 return 0;
2439
2440 return layer->data[pos];
2441 }
2442
2443 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2444 {
2445 if(map<0)
2446 map=cursor.map;
2447
2448 if(scr<0)
2449 scr=cursor.screen;
2450
2451 mapscr *screen1;
2452
2453 if(prv_mode)
2454 {
2455 screen1=get_prvscr();
2456 }
2457 else
2458 {
2459 screen1=AbsoluteScr(cursor.map,cursor.screen);
2460 }
2461
2462 x = vbound(x, 0, 16*16);
2463 y = vbound(y, 0, 11*16);
2464 int32_t combo = COMBOPOS(x,y);
2465
2466 if(combo>175 || combo < 0)
2467 return 0;
2468
2469 return screen1->data[combo];
2470 }
2471
2472 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2473 {
2474 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2475 }
2476
2477 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2478 {
2479 if (map < 0 || screen < 0) return 0;
2480
2481 if(pos>175 || pos < 0)
2482 return 0;
2483
2484 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2485
2486 if (!m->is_valid()) return 0;
2487
2488 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2489
2490 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2491
2492 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2493
2494 if (!scr->is_valid()) return 0;
2495
2496 return scr->sflag[pos]; // entire combo code
2497 }
2498
2499 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2500 {
2501 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2502
2503 if(map<0)
2504 map=cursor.map;
2505
2506 if(scr<0)
2507 scr=cursor.screen;
2508
2509 mapscr *screen1;
2510
2511 if(prv_mode)
2512 {
2513 screen1=get_prvscr();
2514 }
2515 else
2516 {
2517 screen1=AbsoluteScr(cursor.map,cursor.screen);
2518 }
2519
2520 int32_t layermap;
2521 layermap=screen1->layermap[lyr]-1;
2522
2523 if(layermap<0 || layermap >= map_count) return 0;
2524
2525 mapscr *layer;
2526
2527 if(prv_mode)
2528 layer = &prvlayers[lyr];
2529 else
2530 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2531
2532 int32_t combo = COMBOPOS(x,y);
2533
2534 if(combo>175 || combo < 0)
2535 return 0;
2536
2537 return layer->sflag[combo];
2538 }
2539
2540 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2541 {
2542 if(map<0)
2543 map=cursor.map;
2544
2545 if(scr<0)
2546 scr=cursor.screen;
2547
2548 mapscr *screen1;
2549
2550 if(prv_mode)
2551 {
2552 screen1=get_prvscr();
2553 }
2554 else
2555 {
2556 screen1=AbsoluteScr(cursor.map,cursor.screen);
2557 }
2558
2559 x = vbound(x, 0, 16*16);
2560 y = vbound(y, 0, 11*16);
2561 int32_t combo = COMBOPOS(x,y);
2562
2563 if(combo>175 || combo < 0)
2564 return 0;
2565
2566 return screen1->sflag[combo];
2567 }
2568
2569 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2570 {
2571 mapscr *layers[7];
2572 mapscr *basescr;
2573 if(prv_mode)
2574 {
2575 layers[0] = &prvscr;
2576 basescr = layers[0];
2577 for(auto q = 1; q < 7; ++q)
2578 {
2579 if(prvlayers[q-1].valid)
2580 layers[q] = &(prvlayers[q-1]);
2581 else layers[q] = NULL;
2582 }
2583 }
2584 else
2585 {
2586 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2587 basescr = layers[0];
2588 for(auto q = 1; q < 7; ++q)
2589 {
2590 int32_t lmap = basescr->layermap[q-1]-1;
2591 int32_t lscr = basescr->layerscreen[q-1];
2592 if(lmap < 0)
2593 layers[q] = NULL;
2594 else layers[q] = AbsoluteScr(lmap, lscr);
2595 }
2596 }
2597 for(auto q = 0; q < 7; ++q)
2598 {
2599 if(!layers[q]) continue;
2600 for(auto pos = 0; pos < 176; ++pos)
2601 {
2602 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2603 if(cmb.type == cTORCH)
2604 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2605 }
2606 }
2607 word maxffc = basescr->numFFC();
2608 for(auto q = 0; q < maxffc; ++q)
2609 {
2610 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2611 if(cmb.type == cTORCH)
2612 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2613 }
2614 }
2615
2616 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2617 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2618 {
2619 newcombo const& cmb = combobuf[cid];
2620 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2621 if(dither)
2622 {
2623 if (LayerDitherSz == 0)
2624 return;
2625 BITMAP* buf = create_bitmap_ex(8,16,16);
2626 clear_bitmap(buf);
2627 overcombo(buf,0,0,cid,cset);
2628 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2629 if(over)
2630 {
2631 if(transp)
2632 {
2633 color_map = trans_table2;
2634 draw_trans_sprite(dest, buf, x, y);
2635 color_map = trans_table;
2636 }
2637 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2638 }
2639 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2640 destroy_bitmap(buf);
2641 }
2642 else if(over)
2643 {
2644 if(transp)
2645 overcombotranslucent(dest,x,y,cid,cset,0);
2646 else overcombo(dest,x,y,cid,cset);
2647 }
2648 else put_combo(dest,x,y,cid,cset,flags,sflag);
2649 }
2650 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2651 {
2652 if(!md) return;
2653
2654 // These should only be drawn for the currently selected layer, not every layer.
2655 SETFLAG(flags, cCSET, false);
2656 SETFLAG(flags, cCTYPE, false);
2657
2658 for (int32_t i = 0; i < 176; i++)
2659 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2660 }
2661 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2662 {
2663 if(!md) return;
2664
2665 // These should only be drawn for the currently selected layer, not every layer.
2666 SETFLAG(flags, cCSET, false);
2667 SETFLAG(flags, cCTYPE, false);
2668
2669 for (int32_t i = 0; i < 176; i++)
2670 {
2671 int data = md->data[i];
2672 if(combo_class_buf[combobuf[data].type].overhead)
2673 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2674 }
2675 }
2676 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2677 {
2678 if(!LayerMaskInt[lyr])
2679 return nullptr;
2680 if(lyr == 0)
2681 return basescr;
2682 int layermap = basescr->layermap[lyr-1]-1;
2683
2684 if(layermap>-1 && layermap<map_count)
2685 {
2686 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2687 return &TheMaps[layerscreen];
2688 }
2689 return nullptr;
2690 }
2691 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2692 {
2693 int num_ffcs = basescr->numFFC();
2694 for(int32_t i=num_ffcs-1; i>=0; i--)
2695 {
2696 auto const& ff = basescr->ffcs[i];
2697 if(ff.data)
2698 {
2699 if(!(ff.flags&ffc_changer))
2700 {
2701 int32_t tx=(ff.x.getInt())+x;
2702 int32_t ty=(ff.y.getInt())+y;
2703
2704 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2705 {
2706 if(ff.flags&ffc_trans)
2707 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2708 else
2709 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2710 }
2711 }
2712 }
2713 }
2714 }
2715 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2716 {
2717 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2718 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2719 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
2720
2721 if(map<0)
2722 map=cursor.map;
2723
2724 if(screen<0)
2725 screen=cursor.screen;
2726
2727 mapscr *basescr;
2728 mapscr* layers[7] = {nullptr};
2729
2730 if(prv_mode)
2731 {
2732 hl_layer = -1;
2733 basescr=get_prvscr();
2734 }
2735 else
2736 {
2737 basescr=AbsoluteScr(map,screen);
2738 }
2739 layers[0] = _zmap_get_lyr_checked(0,basescr);
2740 for(int lyr = 1; lyr < 7; ++lyr)
2741 {
2742 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2743 : _zmap_get_lyr_checked(lyr,basescr);
2744 }
2745
2746 if(!(basescr->valid&mVALID))
2747 {
2748 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2749 rectfill(dest,x,y,x+255,y+175,vc(1));
2750
2751 if(ShowMisalignments)
2752 {
2753 check_alignments(dest,x,y,screen);
2754 }
2755
2756 return;
2757 }
2758
2759 if(LayerMaskInt[0]==0 || !get_qr(qr_CLASSIC_DRAWING_ORDER))
2760 {
2761 byte bgfill = 0;
2762 if (LayerDitherBG > -1)
2763 bgfill = vc(LayerDitherBG);
2764 rectfill(dest,x,y,x+255,y+175,bgfill);
2765 }
2766
2767 if(olddraw)
2768 {
2769 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2770 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2771 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2772 }
2773 else for (int lyr = -7; lyr < -3; ++lyr)
2774 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, lyr);
2775
2776 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2777 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2778 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2779
2780 if(!olddraw)
2781 {
2782 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2783 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2784 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2785 }
2786 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2787
2788 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !olddraw || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2789 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2790
2791
2792 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2793 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2794
2795 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2796 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2797 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2798
2799 struct DoorDrawData
2800 {
2801 int over_pos; // Position for over_door (dBOMB)
2802 int put_pos; // Position for put_door (standard doors)
2803 int walk_x; // Pre-calculated X offset for dWALK
2804 int walk_y; // Pre-calculated Y offset for dWALK
2805 };
2806
2807 static const DoorDrawData door_data[4] = {
2808 // over, put, walk_x, walk_y
2809 { 39, 7, 120, 16 }, // up
2810 { 135, 151, 120, 144 }, // down
2811 { 66, 64, 16, 80 }, // left
2812 { 77, 78, 224, 80 } // right
2813 };
2814
2815 auto door_set = DoorComboSets[screens[cursor.screen].door_combo_set];
2816 bool walk_trans = get_bit(door_set.flags, df_walktrans);
2817
2818 int32_t doortype[4];
2819 for(int32_t i=0; i<4; i++)
2820 {
2821 switch(basescr->door[i])
2822 {
2823 case dOPEN: doortype[i]=dt_pass; break;
2824 case dLOCKED: doortype[i]=dt_lock; break;
2825 case d1WAYSHUTTER:
2826 case dSHUTTER: doortype[i]=dt_shut; break;
2827 case dBOSS: doortype[i]=dt_boss; break;
2828 case dBOMB: doortype[i]=dt_bomb; break;
2829 default: doortype[i]=0; // Default or unhandled
2830 }
2831 }
2832
2833 for (int i = 0; i < 4; ++i)
2834 {
2835 const auto& d = door_data[i];
2836 const int current_door_type_id = basescr->door[i];
2837
2838 switch (current_door_type_id) {
2839 case dBOMB:
2840 // Draw bombable overlay, then fall through to draw the door
2841 over_door(dest, d.over_pos, i, x, y, false, screen);
2842 [[fallthrough]];
2843
2844 case dOPEN:
2845 case dLOCKED:
2846 case d1WAYSHUTTER:
2847 case dSHUTTER:
2848 case dBOSS:
2849 {
2850 put_door(dest, d.put_pos, i, doortype[i], x, y, false, screen);
2851 break;
2852 }
2853
2854 case dWALK:
2855 if (walk_trans) {
2856 overcombo(dest, d.walk_x + x, d.walk_y + y,
2857 door_set.walkthroughcombo[i],
2858 door_set.walkthroughcset[i]);
2859 } else {
2860 put_combo(dest, d.walk_x + x, d.walk_y + y,
2861 door_set.walkthroughcombo[i],
2862 door_set.walkthroughcset[i], 0, 0);
2863 }
2864 break;
2865 }
2866 }
2867
2868 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2869 {
2870 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2871 }
2872
2873 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2874 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2875 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2876
2877 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2878 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2879
2880 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2881
2882 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2883 {
2884 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2885 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2886 }
2887 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2888 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2889
2890 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2891
2892 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2893 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2894 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2895
2896 int num_ffcs = basescr->numFFC();
2897 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2898 if(basescr->ffcs[i].data)
2899 if(basescr->ffcs[i].flags&ffc_changer)
2900 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2901
2902 if(flags&cWALK)
2903 {
2904 if(layers[0])
2905 for(int32_t i=0; i<176; i++)
2906 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2907
2908 for(int32_t k=0; k<2; k++)
2909 {
2910 if(layers[k+1])
2911 for(int32_t i=0; i<176; i++)
2912 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2913 }
2914 for(int32_t i=num_ffcs-1; i>=0; i--)
2915 {
2916 if(auto data = basescr->ffcs[i].data)
2917 {
2918 if(!(basescr->ffcs[i].flags&ffc_changer))
2919 {
2920 newcombo const& cmb = combobuf[data];
2921 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2922 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2923
2924 if(basescr->ffcs[i].flags&ffc_solid)
2925 {
2926 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2927 }
2928
2929 if(cmb.type == cSLOPE)
2930 {
2931 slope_info s(cmb, tx, ty);
2932 s.draw(dest, 0, 0, COLOR_SLOPE);
2933 }
2934 }
2935 }
2936 }
2937 }
2938
2939 if(flags&(cFLAGS|cCSET|cCTYPE))
2940 {
2941 if(LayerMaskInt[CurrentLayer]!=0)
2942 {
2943 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2944 auto* scr = _lscr>-1 && _lscr<map_count*MAPSCRS ? &TheMaps[_lscr] : nullptr;
2945
2946 for(int32_t i=0; i<176; i++)
2947 {
2948 if(CurrentLayer==0)
2949 {
2950 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2951 }
2952 else
2953 {
2954 if(prv_mode)
2955 {
2956 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2957 }
2958 else if(basescr->layermap[CurrentLayer-1] > 0)
2959 {
2960 if(scr)
2961 {
2962 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2963 scr->data[i],
2964 scr->cset[i], flags,
2965 scr->sflag[i]);
2966 }
2967 }
2968 }
2969 }
2970 }
2971 }
2972
2973 int32_t dark = basescr->flags&cDARK;
2974
2975 if(dark && !(flags&cNODARK)
2976 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2977 {
2978 int col = vc(blackout_color);
2979 for(int32_t j=0; j<80; j++) {
2980 // Logic: ((i^j)&1)==0 means parity matches
2981 int start = (j&1);
2982 for(int32_t i=start; i<(80)-j; i+=2) {
2983 putpixel(dest,x+i,y+j,col);
2984 }
2985 }
2986 }
2987
2988 if(ShowMisalignments)
2989 {
2990 check_alignments(dest,x,y,screen);
2991 }
2992 }
2993
2994 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
2995 {
2996 if(map<0)
2997 map=cursor.map;
2998
2999 if(scr<0)
3000 scr=cursor.screen;
3001
3002 mapscr* layer=AbsoluteScr(map,scr);
3003 int32_t layermap=0, layerscreen=0;
3004
3005 if(!(layer->valid&mVALID))
3006 {
3007 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3008 rectfill(dest,x,y,x+255,y+15,vc(1));
3009 return;
3010 }
3011
3012 int32_t dark = layer->flags&4;
3013
3014 if(LayerMaskInt[0]==0)
3015 {
3016 rectfill(dest,x,y,x+255,y+15,0);
3017 }
3018
3019 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3020 int order[2] = {2,1};
3021 if (olddraw) zc_swap(order[0],order[1]);
3022 for(int k : order)
3023 {
3024 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3025 {
3026 layermap=layer->layermap[k]-1;
3027
3028 if(layermap>-1 && layermap<map_count)
3029 {
3030 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3031
3032 for(int32_t i=c; i<(c&0xF0)+16; i++)
3033 {
3034 auto data = TheMaps[layerscreen].data[i];
3035 auto cs = TheMaps[layerscreen].cset[i];
3036 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3037 }
3038 }
3039 }
3040 }
3041
3042 if(LayerMaskInt[0]!=0)
3043 {
3044 for(int32_t i=c; i<(c&0xF0)+16; i++)
3045 {
3046 word cmbdat = (i < 176 ? layer->data[i] : 0);
3047 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3048 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3049 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3050 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3051 }
3052 }
3053
3054 for(int32_t k=0; k<2; k++)
3055 {
3056 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3057 {
3058 layermap=layer->layermap[k]-1;
3059
3060 if(layermap>-1 && layermap<map_count)
3061 {
3062 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3063
3064 for(int32_t i=c; i<(c&0xF0)+16; i++)
3065 {
3066 auto data = TheMaps[layerscreen].data[i];
3067 auto cs = TheMaps[layerscreen].cset[i];
3068 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3069 }
3070 }
3071 }
3072 }
3073
3074 int32_t doortype[4];
3075
3076 for(int32_t i=0; i<4; i++)
3077 {
3078 switch(layer->door[i])
3079 {
3080 case dOPEN:
3081 doortype[i]=dt_pass;
3082 break;
3083
3084 case dLOCKED:
3085 doortype[i]=dt_lock;
3086 break;
3087
3088 case d1WAYSHUTTER:
3089 case dSHUTTER:
3090 doortype[i]=dt_shut;
3091 break;
3092
3093 case dBOSS:
3094 doortype[i]=dt_boss;
3095 break;
3096
3097 case dBOMB:
3098 doortype[i]=dt_bomb;
3099 break;
3100 }
3101 }
3102
3103 if(c<16)
3104 {
3105 switch(layer->door[up])
3106 {
3107 case dBOMB:
3108 case dOPEN:
3109 case dLOCKED:
3110 case d1WAYSHUTTER:
3111 case dSHUTTER:
3112 case dBOSS:
3113 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3114 break;
3115 }
3116 }
3117 else if(c>159)
3118 {
3119 switch(layer->door[down])
3120 {
3121 case dBOMB:
3122 case dOPEN:
3123 case dLOCKED:
3124 case d1WAYSHUTTER:
3125 case dSHUTTER:
3126 case dBOSS:
3127 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3128 break;
3129 }
3130 }
3131
3132 for(int32_t k=2; k<4; k++)
3133 {
3134 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3135 {
3136 layermap=layer->layermap[k]-1;
3137
3138 if(layermap>-1 && layermap<map_count)
3139 {
3140 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3141
3142 for(int32_t i=c; i<(c&0xF0)+16; i++)
3143 {
3144 if(layer->layeropacity[k]<255)
3145 {
3146 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3147 }
3148 else
3149 {
3150 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3151 }
3152 }
3153 }
3154 }
3155 }
3156
3157 //Overhead L0
3158 if(LayerMaskInt[0]!=0)
3159 {
3160 for(int32_t i=c; i<(c&0xF0)+16; i++)
3161 {
3162 int32_t ct1=layer->data[i];
3163 int32_t ct3=combobuf[ct1].type;
3164
3165 if(combo_class_buf[ct3].overhead)
3166 {
3167 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3168 }
3169 }
3170 }
3171
3172 //Overhead L1/2
3173 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3174 {
3175 for(int32_t k = 0; k < 2; ++k)
3176 {
3177 if(LayerMaskInt[k+1]!=0)
3178 {
3179 layermap=layer->layermap[k]-1;
3180
3181 if(layermap>-1 && layermap<map_count)
3182 {
3183 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3184 for(int32_t i=c; i<(c&0xF0)+16; i++)
3185 {
3186 auto data = TheMaps[layerscreen].data[i];
3187 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3188 auto cs = TheMaps[layerscreen].cset[i];
3189 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3190 }
3191 }
3192 }
3193 }
3194 }
3195
3196 for(int32_t k=4; k<6; k++)
3197 {
3198 if(LayerMaskInt[k+1]!=0)
3199 {
3200 layermap=layer->layermap[k]-1;
3201
3202 if(layermap>-1 && layermap<map_count)
3203 {
3204 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3205
3206 for(int32_t i=c; i<(c&0xF0)+16; i++)
3207 {
3208 auto data = TheMaps[layerscreen].data[i];
3209 auto cs = TheMaps[layerscreen].cset[i];
3210 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3211 }
3212 }
3213 }
3214 }
3215
3216 if(flags&cWALK)
3217 {
3218 if(LayerMaskInt[0]!=0)
3219 {
3220 for(int32_t i=c; i<(c&0xF0)+16; i++)
3221 {
3222 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3223 }
3224 }
3225
3226 for(int32_t k=0; k<2; k++)
3227 {
3228 if(LayerMaskInt[k+1]!=0)
3229 {
3230 for(int32_t i=c; i<(c&0xF0)+16; i++)
3231 {
3232 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3233 }
3234 }
3235 }
3236 }
3237
3238 if(flags&(cFLAGS|cCSET|cCTYPE))
3239 {
3240 if(LayerMaskInt[CurrentLayer]!=0)
3241 {
3242 for(int32_t i=c; i<(c&0xF0)+16; i++)
3243 {
3244 if(CurrentLayer==0)
3245 {
3246 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3247 }
3248 else
3249 {
3250 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3251
3252 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3253 {
3254 if(i < 176)
3255 {
3256 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3257 TheMaps[_lscr].data[i],
3258 TheMaps[_lscr].cset[i], flags|dark,
3259 TheMaps[_lscr].sflag[i]);
3260 }
3261 else
3262 {
3263 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3264 }
3265 }
3266 }
3267 }
3268 }
3269
3270 /*
3271 if (LayerMaskInt[0]!=0) {
3272 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3273 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3274 }
3275 }
3276 */
3277 }
3278
3279 if(ShowMisalignments)
3280 {
3281 if(c<16)
3282 {
3283 check_alignments(dest,x,y,scr);
3284 }
3285 else if(c>159)
3286 {
3287 check_alignments(dest,x,y-160,scr);
3288 }
3289 }
3290 }
3291
3292 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3293 {
3294 if(map<0)
3295 map=cursor.map;
3296
3297 if(scr<0)
3298 scr=cursor.screen;
3299
3300 mapscr* layer=AbsoluteScr(map,scr);
3301 int32_t layermap=0, layerscreen=0;
3302
3303 if(!(layer->valid&mVALID))
3304 {
3305 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3306 rectfill(dest,x,y,x+15,y+175,vc(1));
3307 return;
3308 }
3309
3310 int32_t dark = layer->flags&4;
3311
3312 if(LayerMaskInt[0]==0)
3313 {
3314 rectfill(dest,x,y,x+15,y+175,0);
3315 }
3316
3317 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3318 int order[2] = {2,1};
3319 if (olddraw) zc_swap(order[0],order[1]);
3320 for(int k : order)
3321 {
3322 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3323 {
3324 layermap=layer->layermap[k]-1;
3325
3326 if(layermap>-1 && layermap<map_count)
3327 {
3328 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3329
3330 for(int32_t i=c; i<176; i+=16)
3331 {
3332 auto data = TheMaps[layerscreen].data[i];
3333 auto cs = TheMaps[layerscreen].cset[i];
3334 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3335 }
3336 }
3337 }
3338 }
3339
3340 if(LayerMaskInt[0]!=0)
3341 {
3342 for(int32_t i=c; i<176; i+=16)
3343 {
3344 word cmbdat = layer->data[i];
3345 byte cmbcset = layer->cset[i];
3346 int32_t cmbflag = layer->sflag[i];
3347 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3348 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3349 }
3350 }
3351
3352 for(int32_t k=0; k<2; k++)
3353 {
3354 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3355 {
3356 layermap=layer->layermap[k]-1;
3357
3358 if(layermap>-1 && layermap<map_count)
3359 {
3360 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3361
3362 for(int32_t i=c; i<176; i+=16)
3363 {
3364 auto data = TheMaps[layerscreen].data[i];
3365 auto cs = TheMaps[layerscreen].cset[i];
3366 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3367 }
3368 }
3369 }
3370 }
3371
3372 int32_t doortype[4];
3373
3374 for(int32_t i=0; i<4; i++)
3375 {
3376 switch(layer->door[i])
3377 {
3378 case dOPEN:
3379 doortype[i]=dt_pass;
3380 break;
3381
3382 case dLOCKED:
3383 doortype[i]=dt_lock;
3384 break;
3385
3386 case d1WAYSHUTTER:
3387 case dSHUTTER:
3388 doortype[i]=dt_shut;
3389 break;
3390
3391 case dBOSS:
3392 doortype[i]=dt_boss;
3393 break;
3394
3395 case dBOMB:
3396 doortype[i]=dt_bomb;
3397 break;
3398 }
3399 }
3400
3401 if((c&0x0F)==0)
3402 {
3403 switch(layer->door[left])
3404 {
3405
3406 case dBOMB:
3407 case dOPEN:
3408 case dLOCKED:
3409 case d1WAYSHUTTER:
3410 case dSHUTTER:
3411 case dBOSS:
3412 // put_door(dest,64,left,doortype[left],x+256,y,true);
3413 put_door(dest,64,left,doortype[left],x,y,true,scr);
3414 break;
3415 }
3416 }
3417 else if((c&0x0F)==15)
3418 {
3419 switch(layer->door[right])
3420 {
3421 case dBOMB:
3422 case dOPEN:
3423 case dLOCKED:
3424 case d1WAYSHUTTER:
3425 case dSHUTTER:
3426 case dBOSS:
3427 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3428 break;
3429 }
3430 }
3431
3432 for(int32_t k=2; k<4; k++)
3433 {
3434 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3435 {
3436 layermap=layer->layermap[k]-1;
3437
3438 if(layermap>-1 && layermap<map_count)
3439 {
3440 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3441
3442 for(int32_t i=c; i<176; i+=16)
3443 {
3444 auto data = TheMaps[layerscreen].data[i];
3445 auto cs = TheMaps[layerscreen].cset[i];
3446 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3447 }
3448 }
3449 }
3450 }
3451
3452 //Overhead L0
3453 if(LayerMaskInt[0]!=0)
3454 {
3455 for(int32_t i=c; i<176; i+=16)
3456 {
3457 auto data = TheMaps[layerscreen].data[i];
3458 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3459 auto cs = TheMaps[layerscreen].cset[i];
3460 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3461 }
3462 }
3463 //Overhead L1/2
3464 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3465 {
3466 for(int32_t k = 0; k < 2; ++k)
3467 {
3468 if(LayerMaskInt[k+1]!=0)
3469 {
3470 layermap=layer->layermap[k]-1;
3471
3472 if(layermap>-1 && layermap<map_count)
3473 {
3474 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3475 for(int32_t i=c; i<176; i+=16)
3476 {
3477 auto data = TheMaps[layerscreen].data[i];
3478 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3479 auto cs = TheMaps[layerscreen].cset[i];
3480 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3481 }
3482 }
3483 }
3484 }
3485 }
3486
3487
3488 for(int32_t k=4; k<6; k++)
3489 {
3490 if(LayerMaskInt[k+1]!=0)
3491 {
3492 layermap=layer->layermap[k]-1;
3493
3494 if(layermap>-1 && layermap<map_count)
3495 {
3496 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3497
3498 for(int32_t i=c; i<176; i+=16)
3499 {
3500 auto data = TheMaps[layerscreen].data[i];
3501 auto cs = TheMaps[layerscreen].cset[i];
3502 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3503 }
3504 }
3505 }
3506 }
3507
3508 if(flags&cWALK)
3509 {
3510 if(LayerMaskInt[0]!=0)
3511 {
3512 for(int32_t i=c&0xF; i<176; i+=16)
3513 {
3514 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3515 }
3516 }
3517
3518 for(int32_t k=0; k<2; k++)
3519 {
3520 if(LayerMaskInt[k+1]!=0)
3521 {
3522 for(int32_t i=c&0xF; i<176; i+=16)
3523 {
3524 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3525 }
3526 }
3527 }
3528 }
3529
3530 if(flags&(cFLAGS|cCSET|cCTYPE))
3531 {
3532 if(LayerMaskInt[CurrentLayer]!=0)
3533 {
3534 for(int32_t i=c; i<176; i+=16)
3535 {
3536 if(CurrentLayer==0)
3537 {
3538 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3539 }
3540 else
3541 {
3542 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3543
3544 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3545 {
3546 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3547 TheMaps[_lscr].data[i],
3548 TheMaps[_lscr].cset[i], flags|dark,
3549 TheMaps[_lscr].sflag[i]);
3550 }
3551 }
3552 }
3553 }
3554 }
3555
3556 if(ShowMisalignments)
3557 {
3558 if((c&0x0F)==0)
3559 {
3560 check_alignments(dest,x,y,scr);
3561 }
3562 else if((c&0x0F)==15)
3563 {
3564 check_alignments(dest,x-240,y,scr);
3565 }
3566 }
3567 }
3568
3569 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3570 {
3571 if(map<0)
3572 map=cursor.map;
3573
3574 if(scr<0)
3575 scr=cursor.screen;
3576
3577 mapscr* layer=AbsoluteScr(map,scr);
3578 int32_t layermap=0, layerscreen=0;
3579
3580 if(!(layer->valid&mVALID))
3581 {
3582 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3583 rectfill(dest,x,y,x+15,y+15,vc(1));
3584 return;
3585 }
3586
3587 int32_t dark = layer->flags&4;
3588
3589 if(LayerMaskInt[0]!=0)
3590 {
3591 rectfill(dest,x,y,x+15,y+15,0);
3592 }
3593
3594 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3595 int order[2] = {2,1};
3596 if (olddraw) zc_swap(order[0],order[1]);
3597 for(int k : order)
3598 {
3599 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3600 {
3601 layermap=layer->layermap[k]-1;
3602
3603 if(layermap>-1 && layermap<map_count)
3604 {
3605 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3606
3607 auto data = TheMaps[layerscreen].data[c];
3608 auto cs = TheMaps[layerscreen].cset[c];
3609 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3610 }
3611 }
3612 }
3613
3614 if(LayerMaskInt[0]!=0)
3615 {
3616 word cmbdat = layer->data[c];
3617 byte cmbcset = layer->cset[c];
3618 int32_t cmbflag = layer->sflag[c];
3619 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3620 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3621 }
3622
3623
3624 for(int32_t k=0; k<2; k++)
3625 {
3626 if(LayerMaskInt[k+1]!=0)
3627 {
3628 layermap=layer->layermap[k]-1;
3629
3630 if(layermap>-1 && layermap<map_count)
3631 {
3632 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3633
3634 auto data = TheMaps[layerscreen].data[c];
3635 auto cs = TheMaps[layerscreen].cset[c];
3636 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3637 }
3638 }
3639 }
3640
3641 for(int32_t k=2; k<4; k++)
3642 {
3643 if(LayerMaskInt[k+1]!=0)
3644 {
3645 layermap=layer->layermap[k]-1;
3646
3647 if(layermap>-1 && layermap<map_count)
3648 {
3649 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3650 auto data = TheMaps[layerscreen].data[c];
3651 auto cs = TheMaps[layerscreen].cset[c];
3652 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3653 }
3654 }
3655 }
3656
3657 //Overhead L0
3658 if(LayerMaskInt[0]!=0)
3659 {
3660 auto data = TheMaps[layerscreen].data[c];
3661 if(combo_class_buf[combobuf[data].type].overhead)
3662 {
3663 auto cs = TheMaps[layerscreen].cset[c];
3664 drawcombo(dest,x,y,data,cs,0,0);
3665 }
3666 }
3667 //Overhead L1/2
3668 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3669 {
3670 for(int32_t k = 0; k < 2; ++k)
3671 {
3672 if(LayerMaskInt[k+1]!=0)
3673 {
3674 layermap=layer->layermap[k]-1;
3675
3676 if(layermap>-1 && layermap<map_count)
3677 {
3678 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3679 auto data = TheMaps[layerscreen].data[c];
3680 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3681 auto cs = TheMaps[layerscreen].cset[c];
3682 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3683 }
3684 }
3685 }
3686 }
3687
3688
3689 for(int32_t k=4; k<6; k++)
3690 {
3691 if(LayerMaskInt[k+1]!=0)
3692 {
3693 layermap=layer->layermap[k]-1;
3694
3695 if(layermap>-1 && layermap<map_count)
3696 {
3697 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3698 auto data = TheMaps[layerscreen].data[c];
3699 auto cs = TheMaps[layerscreen].cset[c];
3700 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3701 }
3702 }
3703 }
3704
3705 if(flags&cWALK)
3706 {
3707 if(LayerMaskInt[0]!=0)
3708 {
3709 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3710 }
3711
3712 for(int32_t k=0; k<2; k++)
3713 {
3714 if(LayerMaskInt[k+1]!=0)
3715 {
3716 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3717 }
3718 }
3719 }
3720
3721 if(flags&(cFLAGS|cCSET|cCTYPE))
3722 {
3723 if(LayerMaskInt[CurrentLayer]!=0)
3724 {
3725 int32_t i = c;
3726 //for(int32_t i=c; i==c; i++)
3727 {
3728 if(CurrentLayer==0)
3729 {
3730 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3731 }
3732 else
3733 {
3734 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3735
3736 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3737 {
3738 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3739 TheMaps[_lscr].data[i],
3740 TheMaps[_lscr].cset[i], flags|dark,
3741 TheMaps[_lscr].sflag[i]);
3742 }
3743 }
3744 }
3745 }
3746 }
3747
3748 if(ShowMisalignments)
3749 {
3750 switch(c)
3751 {
3752 case 0:
3753 check_alignments(dest,x,y,scr);
3754 break;
3755
3756 case 15:
3757 check_alignments(dest,x-240,y,scr);
3758 break;
3759
3760 case 160:
3761 check_alignments(dest,x,y-160,scr);
3762 break;
3763
3764 case 175:
3765 check_alignments(dest,x-240,y-160,scr);
3766 break;
3767 }
3768 }
3769 }
3770
3771 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3772 {
3773 if (InvalidBG == 2)
3774 {
3775 draw_checkerboard(dest, x, y, 16);
3776 }
3777 else if(InvalidBG == 1)
3778 {
3779 draw_static(dest, x, y, 16, 16);
3780 }
3781 else
3782 {
3783 rectfill(dest, x, y, x+15, y+15, vc(0));
3784 rect(dest, x, y, x+15, y+15, vc(15));
3785 line(dest, x, y, x+15, y+15, vc(15));
3786 line(dest, x, y+15, x+15, y, vc(15));
3787 }
3788 }
3789
3790 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3791 {
3792 if (InvalidBG == 2)
3793 {
3794 for(int32_t q = 0; q < 11; ++q)
3795 draw_checkerboard(dest, x, y + q * 16, 16);
3796 }
3797 else if(InvalidBG == 1)
3798 {
3799 draw_static(dest, x, y, 16, 176);
3800 }
3801 else
3802 {
3803 rectfill(dest, x, y, x+15, y+175, vc(0));
3804 rect(dest, x, y, x+15, y+175, vc(15));
3805 line(dest, x, y, x+15, y+175, vc(15));
3806 line(dest, x, y+175, x+15, y, vc(15));
3807 }
3808 }
3809
3810 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3811 {
3812 if (InvalidBG == 2)
3813 {
3814 for (int32_t q = 0; q < 16; ++q)
3815 draw_checkerboard(dest, x + q * 16, y, 16);
3816 }
3817 else if(InvalidBG == 1)
3818 {
3819 draw_static(dest, x, y, 256, 16);
3820 }
3821 else
3822 {
3823 rectfill(dest, x, y, x+255, y+15, vc(0));
3824 rect(dest, x, y, x+255, y+15, vc(15));
3825 line(dest, x, y, x+255, y+15, vc(15));
3826 line(dest, x, y+15, x+255, y, vc(15));
3827 }
3828 }
3829
3830 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3831 {
3832 for(int32_t i=0; i<176; i++)
3833 {
3834 word cmbdat = screens[TEMPLATE].data[i];
3835 byte cmbcset = screens[TEMPLATE].cset[i];
3836 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3837 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3838 }
3839 }
3840
3841 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3842 {
3843 for(int32_t i=0; i<176; i++)
3844 {
3845 word cmbdat = screens[TEMPLATE2].data[i];
3846 byte cmbcset = screens[TEMPLATE2].cset[i];
3847 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3848 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3849 }
3850 }
3851
3852 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3853 {
3854 word cmbdat = screens[TEMPLATE].data[pos];
3855 byte cmbcset = screens[TEMPLATE].cset[pos];
3856 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3857 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3858 }
3859
3860 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3861 {
3862 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3863 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3864 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3865 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3866 }
3867
3868 void zmap::scroll(int32_t dir, bool warp)
3869 {
3870 if(cursor.map<map_count)
3871 {
3872 switch(dir)
3873 {
3874 case up:
3875 if(warp && Map.CurrScr()->flags2&wfUP)
3876 {
3877 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3878 }
3879 else if(cursor.screen>15)
3880 {
3881 setCurrScr(cursor.screen - 16);
3882 }
3883
3884 break;
3885
3886 case down:
3887 if(warp && Map.CurrScr()->flags2&wfDOWN)
3888 {
3889 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3890 }
3891 else if(cursor.screen<MAPSCRS-16)
3892 {
3893 setCurrScr(cursor.screen + 16);
3894 }
3895
3896 break;
3897
3898 case left:
3899 if(warp && Map.CurrScr()->flags2&wfLEFT)
3900 {
3901 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3902 }
3903 else if(cursor.screen&15)
3904 {
3905 setCurrScr(cursor.screen - 1);
3906 }
3907
3908 break;
3909
3910 case right:
3911 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3912 {
3913 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3914 }
3915 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3916 {
3917 setCurrScr(cursor.screen + 1);
3918 }
3919
3920 break;
3921 }
3922 }
3923 }
3924
3925 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3926 {
3927 switch(side)
3928 {
3929 case up:
3930 switch(door)
3931 {
3932 case dWALL:
3933 case dBOMB:
3934 case dWALK:
3935 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3936 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3937 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3938 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3939 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3940 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3941 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3942 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3943 break;
3944
3945 default:
3946 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3947 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3948 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3949 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
3950 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
3951 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
3952 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
3953 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
3954 break;
3955 }
3956
3957 break;
3958
3959 case down:
3960 switch(door)
3961 {
3962 case dWALL:
3963 case dBOMB:
3964 case dWALK:
3965 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
3966 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
3967 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
3968 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
3969 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
3970 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
3971 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
3972 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
3973 break;
3974
3975 default:
3976 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
3977 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
3978 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
3979 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
3980 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
3981 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
3982 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
3983 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
3984 break;
3985 }
3986
3987 break;
3988
3989 case left:
3990 switch(door)
3991 {
3992 case dWALL:
3993 case dBOMB:
3994 case dWALK:
3995 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
3996 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
3997 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
3998 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
3999 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4000 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4001 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4002 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4003 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4004 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4005 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4006 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4007 break;
4008
4009 default:
4010 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4011 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4012 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4013 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4014 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4015 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4016 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4017 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4018 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4019 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4020 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4021 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4022 break;
4023 }
4024
4025 break;
4026
4027 case right:
4028 switch(door)
4029 {
4030 case dWALL:
4031 case dBOMB:
4032 case dWALK:
4033 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4034 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4035 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4036 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4037 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4038 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4039 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4040 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4041 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4042 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4043 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4044 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4045 break;
4046
4047 default:
4048 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4049 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4050 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4051 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4052 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4053 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4054 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4055 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4056 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4057 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4058 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4059 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4060 break;
4061 }
4062
4063 break;
4064 }
4065 }
4066 void zmap::DoPutDoorCommand(int side, int door, bool force)
4067 {
4068 if(!force && screens[cursor.screen].door[side] == door)
4069 return;
4070 bool already_list = InListCommand();
4071 if(!already_list)
4072 StartListCommand();
4073 DoSetDoorCommand(cursor.screen,side,door);
4074 if(door != dNONE)
4075 {
4076 word data[176] = {0};
4077 byte cset[176] = {0};
4078 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4079 for(int q = 0; q < 176; ++q)
4080 if(data[q])
4081 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4082 }
4083 if(!already_list)
4084 FinishListCommand();
4085 }
4086 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4087 {
4088 if(screens[screen].door[side] == door)
4089 return;
4090
4091 screens[screen].door[side] = door;
4092 if(door != dNONE)
4093 {
4094 word data[176] = {0};
4095 byte cset[176] = {0};
4096 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4097 for(int q = 0; q < 176; ++q)
4098 if(data[q])
4099 {
4100 screens[screen].data[q] = data[q];
4101 screens[screen].cset[q] = cset[q];
4102 }
4103 }
4104 }
4105
4106 void list_command::execute()
4107 {
4108 for (auto command : commands)
4109 {
4110 command->execute();
4111 }
4112 }
4113
4114 void list_command::undo()
4115 {
4116 for (int i = commands.size() - 1; i >= 0; i--)
4117 {
4118 commands[i]->undo();
4119 }
4120 }
4121
4122 int list_command::size()
4123 {
4124 int s = 0;
4125 for (auto command : commands)
4126 {
4127 s += command->size();
4128 }
4129 return s;
4130 }
4131
4132 void set_combo_command::execute()
4133 {
4134 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4135 if (!scr_ptr) return;
4136
4137 if (combo != -1) scr_ptr->data[pos] = combo;
4138 scr_ptr->cset[pos] = cset;
4139 }
4140
4141 void set_combo_command::undo()
4142 {
4143 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4144 if(!mapscr_ptr) return;
4145 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4146 mapscr_ptr->cset[pos] = prev_cset;
4147 }
4148
4149 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4150 {
4151 std::array<int, 8> initd_arr;
4152 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4153
4154 return {
4155 .x = ffc.x,
4156 .y = ffc.y,
4157 .vx = ffc.vx,
4158 .vy = ffc.vy,
4159 .ax = ffc.ax,
4160 .ay = ffc.ay,
4161 .data = ffc.data,
4162 .cset = ffc.cset,
4163 .delay = ffc.delay,
4164 .link = ffc.link,
4165 .script = ffc.script,
4166 .tw = ffc.txsz,
4167 .th = ffc.tysz,
4168 .ew = ffc.hit_width,
4169 .eh = ffc.hit_height,
4170 .flags = ffc.flags,
4171 .initd = initd_arr,
4172 .layer = ffc.layer
4173 };
4174 }
4175
4176 void set_ffc_command::execute()
4177 {
4178 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4179 if(!mapscr_ptr) return;
4180
4181 mapscr_ptr->valid |= mVALID;
4182 mapscr_ptr->ffcs[i].x = data.x;
4183 mapscr_ptr->ffcs[i].y = data.y;
4184 mapscr_ptr->ffcs[i].vx = data.vx;
4185 mapscr_ptr->ffcs[i].vy = data.vy;
4186 mapscr_ptr->ffcs[i].ax = data.ax;
4187 mapscr_ptr->ffcs[i].ay = data.ay;
4188 mapscr_ptr->ffcs[i].data = data.data;
4189 mapscr_ptr->ffcs[i].cset = data.cset;
4190 mapscr_ptr->ffcs[i].delay = data.delay;
4191 mapscr_ptr->ffcs[i].link = data.link;
4192 mapscr_ptr->ffcs[i].script = data.script;
4193 mapscr_ptr->ffcs[i].flags = data.flags;
4194 mapscr_ptr->ffEffectWidth(i, data.ew);
4195 mapscr_ptr->ffEffectHeight(i, data.eh);
4196 mapscr_ptr->ffTileWidth(i, data.tw);
4197 mapscr_ptr->ffTileHeight(i, data.th);
4198 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4199 mapscr_ptr->ffcs[i].layer = data.layer;
4200 mapscr_ptr->ffcCountMarkDirty();
4201 mapscr_ptr->ffcs[i].updateSolid();
4202 }
4203
4204 void set_ffc_command::undo()
4205 {
4206 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4207 if(!mapscr_ptr) return;
4208
4209 mapscr_ptr->ffcs[i].x = prev_data.x;
4210 mapscr_ptr->ffcs[i].y = prev_data.y;
4211 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4212 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4213 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4214 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4215 mapscr_ptr->ffcs[i].data = prev_data.data;
4216 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4217 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4218 mapscr_ptr->ffcs[i].link = prev_data.link;
4219 mapscr_ptr->ffcs[i].script = prev_data.script;
4220 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4221 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4222 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4223 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4224 mapscr_ptr->ffTileHeight(i, prev_data.th);
4225 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4226 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4227 mapscr_ptr->ffcCountMarkDirty();
4228 mapscr_ptr->ffcs[i].updateSolid();
4229 }
4230
4231 void set_flag_command::execute()
4232 {
4233 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4234 if(!mapscr_ptr) return;
4235
4236 mapscr_ptr->valid |= mVALID;
4237 mapscr_ptr->sflag[pos] = flag;
4238 }
4239
4240 void set_flag_command::undo()
4241 {
4242 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4243 if(!mapscr_ptr) return;
4244 mapscr_ptr->sflag[pos] = prev_flag;
4245 }
4246
4247 void set_door_command::execute()
4248 {
4249 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4250 if(!mapscr_ptr) return;
4251
4252 mapscr_ptr->valid |= mVALID;
4253 mapscr_ptr->door[side] = door;
4254 }
4255
4256 void set_door_command::undo()
4257 {
4258 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4259 }
4260
4261 void set_dcs_command::execute()
4262 {
4263 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4264 if(!mapscr_ptr) return;
4265
4266 mapscr_ptr->valid |= mVALID;
4267 mapscr_ptr->door_combo_set = dcs;
4268 }
4269
4270 void set_dcs_command::undo()
4271 {
4272 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4273 }
4274
4275 void paste_screen_command::execute()
4276 {
4277 perform(screen.get());
4278 }
4279
4280 void paste_screen_command::undo()
4281 {
4282 if (prev_screens.size() > 1)
4283 {
4284 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4285 ASSERT(prev_screens.size() == 128);
4286 for (int i = 0; i < 128; i++)
4287 {
4288 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4289 // TODO: why not just this?
4290 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4291 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4292 }
4293 return;
4294 }
4295
4296 perform(prev_screens[0].get());
4297 }
4298
4299 int paste_screen_command::size()
4300 {
4301 return prev_screens.size() + 1;
4302 }
4303
4304 void paste_screen_command::perform(mapscr* to)
4305 {
4306 if (to)
4307 {
4308 switch (type) {
4309 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4310 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4311 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4312 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4313 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4314 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4315 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4316 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4317 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4318 case ScreenPartial: Map.Paste(*to, screen_index); break;
4319 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4320 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4321 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4322 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4323 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4324 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4325 }
4326 }
4327 else
4328 {
4329 Map.clearscr(screen_index);
4330 }
4331 refresh(rALL);
4332 }
4333
4334 void set_screen_command::execute()
4335 {
4336 if (screen)
4337 {
4338 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4339 }
4340 else
4341 {
4342 Map.clearscr(screen_index);
4343 }
4344 refresh(rALL);
4345 }
4346
4347 void set_screen_command::undo()
4348 {
4349 if (prev_screen)
4350 {
4351 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4352 }
4353 else
4354 {
4355 Map.clearscr(screen_index);
4356 }
4357 refresh(rALL);
4358 }
4359
4360 int set_screen_command::size()
4361 {
4362 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4363 }
4364
4365 static std::shared_ptr<list_command> current_list_command;
4366 void zmap::StartListCommand()
4367 {
4368 ASSERT(!current_list_command);
4369 current_list_command.reset(new list_command);
4370 }
4371
4372 void zmap::FinishListCommand()
4373 {
4374 if (current_list_command->commands.size() == 1)
4375 {
4376 input_undo_stack.push_back(current_list_command->commands[0]);
4377 }
4378 else if (current_list_command->commands.size() > 1)
4379 {
4380 input_undo_stack.push_back(current_list_command);
4381 }
4382 CapCommandHistory();
4383 current_list_command = nullptr;
4384 }
4385
4386 void zmap::RevokeListCommand()
4387 {
4388 current_list_command->undo();
4389 current_list_command = nullptr;
4390 }
4391
4392 bool zmap::InListCommand() const
4393 {
4394 return current_list_command ? true : false;
4395 }
4396
4397 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4398 {
4399 input_redo_stack = {};
4400
4401 if (!skip_execute) command->execute();
4402 if (current_list_command)
4403 {
4404 current_list_command->commands.push_back(command);
4405 if (current_list_command->commands.size() == 1)
4406 {
4407 current_list_command->cursor = command->cursor;
4408 }
4409 }
4410 else
4411 {
4412 input_undo_stack.push_back(command);
4413 CapCommandHistory();
4414 }
4415 mark_save_dirty();
4416 }
4417
4418 void zmap::UndoCommand()
4419 {
4420 if (input_undo_stack.size() <= 0) return;
4421
4422 // If not currently looking at the associated screen, first change the view
4423 // and wait for the next call to actually undo this command.
4424 auto command = input_undo_stack.back();
4425 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4426 {
4427 setCursor(command.get()->cursor);
4428 return;
4429 }
4430
4431 command->undo();
4432 input_redo_stack.push(command);
4433 input_undo_stack.pop_back();
4434 mark_save_dirty();
4435 }
4436
4437 void zmap::RedoCommand()
4438 {
4439 if (input_redo_stack.size() <= 0) return;
4440
4441 // If not currently selected the associated screen, first change the cursor
4442 // and wait for the next call to actually execute this command.
4443 auto command = input_redo_stack.top();
4444 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4445 {
4446 setCursor(command.get()->cursor);
4447 return;
4448 }
4449
4450 command->execute();
4451 input_undo_stack.push_back(command);
4452 input_redo_stack.pop();
4453 mark_save_dirty();
4454 }
4455
4456 11 void zmap::ClearCommandHistory()
4457 {
4458 11 current_list_command = nullptr;
4459 11 input_undo_stack = {};
4460 11 input_redo_stack = {};
4461 11 }
4462
4463 // Extra amount is from mapscr's vectors.
4464 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4465 // Allow the undo system to use roughly 100 MB of memory.
4466 // This doesn't count the memory used by commands that don't store a mapscr,
4467 // but that should be negligible.
4468 12 static int max_command_size = 100e6 / size_of_mapscr;
4469 void zmap::CapCommandHistory()
4470 {
4471 int size;
4472 do
4473 {
4474 size = 0;
4475 for (auto command : input_undo_stack)
4476 {
4477 size += command->size();
4478 }
4479 if (size > max_command_size) input_undo_stack.pop_front();
4480 } while (size > max_command_size);
4481 }
4482
4483 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4484 {
4485 if (!pos.is_valid(cursor))
4486 return;
4487
4488 int map = cursor.map;
4489 int screen = cursor.viewscr + pos.screen_offset();
4490 if (!AbsoluteScr(map, screen))
4491 return;
4492
4493 if (CurrentLayer)
4494 {
4495 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4496 map = scr->layermap[CurrentLayer-1]-1;
4497 screen = scr->layerscreen[CurrentLayer-1];
4498 }
4499 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4500 }
4501
4502 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4503 {
4504 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4505 if (!mapscr_ptr) return;
4506
4507 std::shared_ptr<set_combo_command> command(new set_combo_command);
4508 command->cursor = cursor;
4509 command->map = map;
4510 command->scr = scr;
4511 command->pos = pos;
4512 command->combo = combo;
4513 command->cset = cset;
4514 command->prev_combo = mapscr_ptr->data[pos];
4515 command->prev_cset = mapscr_ptr->cset[pos];
4516 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4517 {
4518 // nothing to do...
4519 return;
4520 }
4521
4522 ExecuteCommand(command);
4523 }
4524
4525 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4526 {
4527 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4528 if(!mapscr_ptr) return;
4529
4530 mapscr_ptr->ensureFFC(i);
4531
4532 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4533
4534 std::array<int, 8> initd_arr;
4535 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4536
4537 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4538
4539 command->cursor = cursor;
4540 command->map = map;
4541 command->scr = scr;
4542 command->i = i;
4543 command->data = data;
4544 command->prev_data = prev_data;
4545 if (data == prev_data)
4546 {
4547 // nothing to do...
4548 return;
4549 }
4550
4551 ExecuteCommand(command);
4552 }
4553
4554 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4555 {
4556 if (!pos.is_valid(cursor))
4557 return;
4558
4559 int map = cursor.map;
4560 int screen = cursor.viewscr + pos.screen_offset();
4561 if (!AbsoluteScr(map, screen))
4562 return;
4563
4564 if (CurrentLayer)
4565 {
4566 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4567 map = scr->layermap[CurrentLayer-1]-1;
4568 screen = scr->layerscreen[CurrentLayer-1];
4569 }
4570 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4571 }
4572
4573 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4574 {
4575 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4576 if(!mapscr_ptr) return;
4577
4578 std::shared_ptr<set_flag_command> command(new set_flag_command);
4579 command->cursor = cursor;
4580 command->map = map;
4581 command->scr = scr;
4582 command->pos = pos;
4583 command->flag = flag;
4584 command->prev_flag = mapscr_ptr->sflag[pos];
4585 if (command->flag == command->prev_flag)
4586 {
4587 // nothing to do...
4588 return;
4589 }
4590
4591 ExecuteCommand(command);
4592 }
4593
4594 void zmap::DoSetDoorCommand(int scr, int side, int door)
4595 {
4596 if(screens[scr].door[side] == door)
4597 return;
4598 std::shared_ptr<set_door_command> command(new set_door_command);
4599 command->cursor = cursor;
4600 command->side = side;
4601 command->door = door;
4602 command->prev_door = screens[scr].door[side];
4603
4604 ExecuteCommand(command);
4605 }
4606 void zmap::DoSetDCSCommand(int dcs)
4607 {
4608 if(screens[cursor.screen].door_combo_set == dcs)
4609 return;
4610 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4611 command->cursor = cursor;
4612 command->dcs = dcs;
4613 command->prev_dcs = screens[cursor.screen].door_combo_set;
4614
4615 ExecuteCommand(command);
4616 }
4617
4618 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4619 {
4620 if (screen == -1)
4621 screen = cursor.screen;
4622
4623 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4624 command->cursor = cursor;
4625 command->type = type;
4626 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4627 command->screen_index = screen;
4628
4629 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4630 {
4631 for (int i=0; i < 128; i++)
4632 {
4633 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4634 }
4635 }
4636 else
4637 {
4638 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4639 }
4640
4641 ExecuteCommand(command);
4642 }
4643
4644 void zmap::DoClearScreenCommand(int screen)
4645 {
4646 std::shared_ptr<set_screen_command> command(new set_screen_command);
4647 command->cursor = cursor;
4648 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4649 command->screen = std::shared_ptr<mapscr>(nullptr);
4650 command->screen_index = screen;
4651
4652 ExecuteCommand(command);
4653 }
4654
4655 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4656 {
4657 std::shared_ptr<set_screen_command> command(new set_screen_command);
4658 command->cursor = cursor;
4659 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4660 Template(floorcombo, floorcset, screen);
4661 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4662
4663 ExecuteCommand(command, true);
4664 }
4665
4666 void zmap::Copy(int scr)
4667 {
4668 if(screens[scr].valid&mVALID)
4669 {
4670 copy_mapscr(&copymapscr, &screens[scr]);
4671 //copymapscr=screens[scr];
4672 can_paste=true;
4673 copymap=cursor.map;
4674 copyscr=scr;
4675 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4676 copyffc = -1;
4677 }
4678 }
4679
4680 void zmap::CopyFFC(int32_t screen, int32_t n)
4681 {
4682 if(screens[screen].valid&mVALID)
4683 {
4684 copy_mapscr(&copymapscr, &screens[screen]);
4685 // Can't paste the screen itself
4686 can_paste = false;
4687 copymap=cursor.map;
4688 copyscr=screen;
4689 copyffc = n;
4690 }
4691 }
4692
4693 void zmap::Paste(const mapscr& copymapscr, int screen)
4694 {
4695 if(can_paste)
4696 {
4697 if(!(screens[screen].valid&mVALID))
4698 {
4699 screens[screen].valid |= mVALID;
4700 screens[screen].color = copymapscr.color;
4701 }
4702
4703 screens[screen].door_combo_set = copymapscr.door_combo_set;
4704
4705 for(int32_t i=0; i<4; i++)
4706 {
4707 screens[screen].door[i]=copymapscr.door[i];
4708 }
4709
4710 for(int32_t i=0; i<176; i++)
4711 {
4712 screens[screen].data[i] = copymapscr.data[i];
4713 screens[screen].cset[i] = copymapscr.cset[i];
4714 screens[screen].sflag[i] = copymapscr.sflag[i];
4715 }
4716
4717 refresh_color();
4718
4719 mark_save_dirty();
4720 }
4721 }
4722
4723 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4724 {
4725 if(can_paste)
4726 {
4727 screens[screen].undercombo = copymapscr.undercombo;
4728 screens[screen].undercset = copymapscr.undercset;
4729 mark_save_dirty();
4730 }
4731 }
4732
4733 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4734 {
4735 if(can_paste)
4736 {
4737 for(int32_t i=0; i<128; i++)
4738 {
4739 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4740 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4741 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4742 }
4743
4744 mark_save_dirty();
4745 }
4746 }
4747
4748 // TODO const mapscr& copymapscr
4749 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4750 {
4751 if(can_paste)
4752 {
4753 screens[screen].ffcs = copymapscr.ffcs;
4754 screens[screen].ffcCountMarkDirty();
4755 mark_save_dirty();
4756 }
4757 }
4758
4759 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4760 {
4761 if(can_paste)
4762 {
4763 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4764
4765 for(int32_t i=0; i<4; i++)
4766 {
4767 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4768 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4769 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4770 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4771 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4772 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4773 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4774 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4775 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4776 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4777 }
4778
4779 mark_save_dirty();
4780 }
4781 }
4782
4783 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4784 {
4785 if(can_paste)
4786 {
4787 screens[screen].csensitive = copymapscr.csensitive;
4788 screens[screen].oceansfx = copymapscr.oceansfx;
4789 screens[screen].bosssfx = copymapscr.bosssfx;
4790 screens[screen].secretsfx = copymapscr.secretsfx;
4791 screens[screen].holdupsfx = copymapscr.holdupsfx;
4792 screens[screen].flags = copymapscr.flags;
4793 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4794 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4795 screens[screen].flags3 = copymapscr.flags3;
4796 screens[screen].flags4 = copymapscr.flags4;
4797 screens[screen].flags5 = copymapscr.flags5;
4798 screens[screen].flags6 = copymapscr.flags6;
4799 screens[screen].flags7 = copymapscr.flags7;
4800 screens[screen].flags8 = copymapscr.flags8;
4801 screens[screen].flags9 = copymapscr.flags9;
4802 screens[screen].flags10 = copymapscr.flags10;
4803 screens[screen].flags11 = copymapscr.flags11;
4804 screens[screen].item = copymapscr.item;
4805 screens[screen].hasitem = copymapscr.hasitem;
4806 screens[screen].itemx = copymapscr.itemx;
4807 screens[screen].itemy = copymapscr.itemy;
4808 screens[screen].nextmap = copymapscr.nextmap;
4809 screens[screen].nextscr = copymapscr.nextscr;
4810 screens[screen].nocarry = copymapscr.nocarry;
4811 screens[screen].noreset = copymapscr.noreset;
4812 screens[screen].exstate_reset = copymapscr.exstate_reset;
4813 screens[screen].exstate_carry = copymapscr.exstate_carry;
4814 screens[screen].path[0] = copymapscr.path[0];
4815 screens[screen].path[1] = copymapscr.path[1];
4816 screens[screen].path[2] = copymapscr.path[2];
4817 screens[screen].path[3] = copymapscr.path[3];
4818 screens[screen].pattern = copymapscr.pattern;
4819 screens[screen].exitdir = copymapscr.exitdir;
4820 screens[screen].music = copymapscr.music;
4821 screens[screen].stairx = copymapscr.stairx;
4822 screens[screen].stairy = copymapscr.stairy;
4823 screens[screen].timedwarptics = copymapscr.timedwarptics;
4824 mark_save_dirty();
4825 }
4826 }
4827
4828 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4829 {
4830 if(can_paste)
4831 {
4832 screens[screen].warpreturnc = copymapscr.warpreturnc;
4833 screens[screen].warparrivalx = copymapscr.warparrivalx;
4834 screens[screen].warparrivaly = copymapscr.warparrivaly;
4835
4836 for(int32_t i=0; i<4; i++)
4837 {
4838 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4839 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4840 }
4841
4842 mark_save_dirty();
4843 }
4844 }
4845
4846 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4847 {
4848 if(can_paste)
4849 {
4850 for(int32_t i=0; i<4; i++)
4851 screens[screen].door[i] = copymapscr.door[i];
4852
4853 screens[screen].door_combo_set = copymapscr.door_combo_set;
4854 mark_save_dirty();
4855 }
4856 }
4857
4858 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4859 {
4860 if(can_paste)
4861 {
4862 for(int32_t i=0; i<6; i++)
4863 {
4864 screens[screen].layermap[i] = copymapscr.layermap[i];
4865 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4866 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4867 }
4868
4869 mark_save_dirty();
4870 }
4871 }
4872
4873 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4874 {
4875 if(can_paste)
4876 {
4877 screens[screen].room = copymapscr.room;
4878 screens[screen].catchall = copymapscr.catchall;
4879 mark_save_dirty();
4880 }
4881 }
4882
4883 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4884 {
4885 if(can_paste)
4886 {
4887 screens[screen].guy = copymapscr.guy;
4888 screens[screen].guytile = copymapscr.guytile;
4889 screens[screen].guycs = copymapscr.guycs;
4890 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4891 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4892 screens[screen].str = copymapscr.str;
4893 mark_save_dirty();
4894 }
4895 }
4896
4897 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4898 {
4899 if(can_paste)
4900 {
4901 screens[screen].color = copymapscr.color;
4902 screens[screen].valid|=mVALID;
4903 refresh_color();
4904
4905 mark_save_dirty();
4906 }
4907 }
4908
4909 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4910 {
4911 if(can_paste)
4912 {
4913 copy_mapscr(&screens[screen], &copymapscr);
4914 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4915 screens[screen].valid|=mVALID;
4916
4917 refresh_color();
4918
4919 mark_save_dirty();
4920 }
4921 }
4922
4923
4924 void zmap::PasteToAll(const mapscr& copymapscr)
4925 {
4926 if(can_paste)
4927 {
4928 for(int32_t x=0; x<128; x++)
4929 {
4930 if(!(screens[x].valid&mVALID))
4931 {
4932 screens[x].valid |= mVALID;
4933 screens[x].color = copymapscr.color;
4934 }
4935
4936 for(int32_t i=0; i<176; i++)
4937 {
4938 screens[x].data[i] = copymapscr.data[i];
4939 screens[x].cset[i] = copymapscr.cset[i];
4940 screens[x].sflag[i] = copymapscr.sflag[i];
4941 }
4942 }
4943
4944 refresh_color();
4945
4946 mark_save_dirty();
4947 }
4948 }
4949
4950 void zmap::PasteAllToAll(const mapscr& copymapscr)
4951 {
4952 if(can_paste)
4953 {
4954 for(int32_t x=0; x<128; x++)
4955 {
4956 copy_mapscr(&screens[x], &copymapscr);
4957 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
4958 //screens[x]=copymapscr;
4959 }
4960
4961 refresh_color();
4962
4963 mark_save_dirty();
4964 }
4965 }
4966
4967 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
4968 {
4969 if(can_paste)
4970 {
4971 for(int32_t i=0; i<10; i++)
4972 screens[screen].enemy[i]=copymapscr.enemy[i];
4973 }
4974 }
4975
4976 bool zmap::CanGoBack() const
4977 {
4978 return !cursor_undo_stack.empty();
4979 }
4980
4981 bool zmap::CanGoForward() const
4982 {
4983 return !cursor_redo_stack.empty();
4984 }
4985
4986 void zmap::GoBack()
4987 {
4988 if (!CanGoBack())
4989 return;
4990
4991 cursor_redo_stack.push(cursor);
4992
4993 ConfigureCursorHistory(false);
4994 setCursor(cursor_undo_stack.back());
4995 ConfigureCursorHistory(true);
4996
4997 cursor_undo_stack.pop_back();
4998 }
4999
5000 void zmap::GoForward()
5001 {
5002 if (!CanGoForward())
5003 return;
5004
5005 cursor_undo_stack.push_back(cursor);
5006
5007 ConfigureCursorHistory(false);
5008 setCursor(cursor_redo_stack.top());
5009 ConfigureCursorHistory(true);
5010
5011 cursor_redo_stack.pop();
5012 }
5013
5014 void zmap::CapCursorHistory()
5015 {
5016 int max_history_size = 1000;
5017 while (cursor_undo_stack.size() > max_history_size)
5018 cursor_undo_stack.pop_front();
5019 }
5020
5021 void zmap::ConfigureCursorHistory(bool enable)
5022 {
5023 cursor_history_enabled = enable;
5024 }
5025
5026 void zmap::setCopyFFC(int32_t n)
5027 {
5028 copyffc = n;
5029 }
5030
5031 void zmap::update_combo_cycling()
5032 {
5033 if(!prv_mode||!prv_cmbcycle)
5034 {
5035 return;
5036 }
5037
5038 int32_t x;
5039 int32_t newdata[176];
5040 int32_t newcset[176];
5041 bool restartanim[MAXCOMBOS] = {0};
5042
5043 for(int32_t i=0; i<176; i++)
5044 {
5045 newdata[i]=-1;
5046 newcset[i]=-1;
5047
5048 x=prvscr.data[i];
5049
5050 //time to restart
5051 if((combobuf[x].aclk>=combobuf[x].speed) &&
5052 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5053 combobuf[x].can_cycle())
5054 {
5055 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5056 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5057
5058 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5059 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5060 int32_t c = newdata[i];
5061
5062 if(combobuf[c].animflags & AF_CYCLE)
5063 {
5064 restartanim[c]=true;
5065 }
5066 }
5067 }
5068
5069 for(int32_t i=0; i<176; i++)
5070 {
5071 x=prvscr.data[i];
5072
5073 //time to restart
5074 if((combobuf[x].aclk>=combobuf[x].speed) &&
5075 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5076 combobuf[x].can_cycle())
5077 {
5078 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5079 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5080
5081 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5082 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5083 int32_t c = newdata[i];
5084
5085 if(combobuf[c].animflags & AF_CYCLE)
5086 {
5087 restartanim[c]=true;
5088 }
5089 }
5090 }
5091
5092 for(int32_t i=0; i<176; i++)
5093 {
5094 if(newdata[i]==-1)
5095 continue;
5096
5097 prvscr.data[i]=newdata[i];
5098 prvscr.cset[i]=newcset[i];
5099 }
5100
5101 word maxffc = prvscr.numFFC();
5102 for(word i=0; i<maxffc; i++)
5103 {
5104 ffcdata& ffc = prvscr.ffcs[i];
5105 newcombo const& cmb = combobuf[ffc.data];
5106
5107 //time to restart
5108 if((cmb.aclk>=cmb.speed) &&
5109 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5110 cmb.can_cycle())
5111 {
5112 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5113 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5114
5115 if(!(cmb.animflags & AF_CYCLENOCSET))
5116 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5117
5118 if(combobuf[ffc.data].animflags & AF_CYCLE)
5119 {
5120 restartanim[ffc.data]=true;
5121 }
5122 prvscr.ffcs[i].data = ffc.data;
5123 prvscr.ffcs[i].cset=ffc.cset;
5124 }
5125 }
5126
5127
5128 if(get_qr(qr_CMBCYCLELAYERS))
5129 {
5130 for(int32_t j=0; j<6; j++)
5131 {
5132 if(!prvlayers[j].valid)
5133 continue;
5134
5135 for(int32_t i=0; i<176; i++)
5136 {
5137 newdata[i]=-1;
5138 newcset[i]=-1;
5139
5140 x=(prvlayers[j]).data[i];
5141
5142 //time to restart
5143 if((combobuf[x].aclk>=combobuf[x].speed) &&
5144 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5145 combobuf[x].can_cycle())
5146 {
5147 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5148 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5149
5150 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5151 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5152 int32_t c = newdata[i];
5153
5154 if(combobuf[c].animflags & AF_CYCLE)
5155 {
5156 restartanim[c]=true;
5157 }
5158 }
5159 }
5160
5161 for(int32_t i=0; i<176; i++)
5162 {
5163 x=(prvlayers[j]).data[i];
5164
5165 //time to restart
5166 if((combobuf[x].aclk>=combobuf[x].speed) &&
5167 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5168 combobuf[x].can_cycle())
5169 {
5170 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5171 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5172
5173 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5174 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5175 int32_t c = newdata[i];
5176
5177 if(combobuf[c].animflags & AF_CYCLE)
5178 {
5179 restartanim[c]=true;
5180 }
5181 }
5182 }
5183
5184 for(int32_t i=0; i<176; i++)
5185 {
5186 if(newdata[i]==-1)
5187 continue;
5188
5189 prvlayers[j].data[i]=newdata[i];
5190 prvlayers[j].cset[i]=newcset[i];
5191 }
5192 }
5193 }
5194
5195 for(int32_t i=0; i<MAXCOMBOS; i++)
5196 {
5197 if(restartanim[i])
5198 {
5199 combobuf[i].tile = combobuf[i].o_tile;
5200 combobuf[i].cur_frame=0;
5201 combobuf[i].aclk = 0;
5202 }
5203 }
5204 }
5205
5206 void zmap::update_freeform_combos()
5207 {
5208 if(!prv_mode||!prv_cmbcycle)
5209 {
5210 return;
5211 }
5212
5213 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5214 word maxffc = prvscr.numFFC();
5215 for(int32_t i=0; i<maxffc; i++)
5216 {
5217 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5218 {
5219 for(int32_t j=0; j<maxffc; j++)
5220 {
5221 if(i!=j)
5222 {
5223 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5224 {
5225 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5226 {
5227 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5228 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5229 {
5230 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5231 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5232 if(prvscr.ffcs[j].flags&ffc_changethis)
5233 {
5234 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5235 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5236 }
5237
5238 if(prvscr.ffcs[j].flags&ffc_changenext)
5239 prvscr.ffcs[i].data += 1;
5240
5241 if(prvscr.ffcs[j].flags&ffc_changeprev)
5242 prvscr.ffcs[i].data -= 1;
5243
5244 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5245 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5246 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5247
5248 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5249 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5250 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5251 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5252
5253 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5254 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5255 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5256 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5257 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5258
5259 if(prvscr.ffcs[i].flags&ffc_carryover)
5260 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5261 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5262
5263 prvscr.ffcs[i].flags&=~ffc_changer;
5264 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5265 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5266
5267 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5268 {
5269 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5270 }
5271
5272 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5273 {
5274 int32_t k=0;
5275
5276 if(prvscr.ffcs[j].flags&ffc_swapnext)
5277 k=j<(MAXFFCS-1)?j+1:0;
5278
5279 if(prvscr.ffcs[j].flags&ffc_swapprev)
5280 k=j>0?j-1:(MAXFFCS-1);
5281
5282 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5283 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5284 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5285 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5286 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5287 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5288 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5289 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5290 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5291 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5292 }
5293 }
5294 }
5295 }
5296 }
5297 }
5298
5299 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5300 {
5301 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5302 {
5303 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5304 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5305 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5306 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5307 }
5308 else
5309 {
5310 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5311 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5312 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5313 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5314 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5315 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5316
5317 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5318 {
5319 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5320
5321 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5322
5323 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5324
5325 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5326 }
5327 }
5328 }
5329 else
5330 {
5331 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5332 prvscr.ffcs[i].delay--;
5333 }
5334
5335 if(prvscr.ffcs[i].x<-32)
5336 {
5337 if(prvscr.flags6&fWRAPAROUNDFF)
5338 {
5339 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5340 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5341 }
5342 else
5343 {
5344 prvscr.ffcs[i].data = 0;
5345 prvscr.ffcs[i].flags&=~ffc_carryover;
5346 }
5347 }
5348
5349 if(prvscr.ffcs[i].y<-32)
5350 {
5351 if(prvscr.flags6&fWRAPAROUNDFF)
5352 {
5353 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5354 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5355 }
5356 else
5357 {
5358 prvscr.ffcs[i].data = 0;
5359 prvscr.ffcs[i].flags&=~ffc_carryover;
5360 }
5361 }
5362
5363 if(prvscr.ffcs[i].x>=288)
5364 {
5365 if(prvscr.flags6&fWRAPAROUNDFF)
5366 {
5367 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5368 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5369 }
5370 else
5371 {
5372 prvscr.ffcs[i].data = 0;
5373 prvscr.ffcs[i].flags&=~ffc_carryover;
5374 }
5375 }
5376
5377 if(prvscr.ffcs[i].y>=208)
5378 {
5379 if(prvscr.flags6&fWRAPAROUNDFF)
5380 {
5381 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5382 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5383 }
5384 else
5385 {
5386 prvscr.ffcs[i].data = 0;
5387 prvscr.ffcs[i].flags&=~ffc_carryover;
5388 }
5389 }
5390
5391 }
5392 }
5393 }
5394
5395 void zmap::goto_dmapscr(int dmap, int scr)
5396 {
5397 goto_mapscr(DMaps[dmap].map, scr + DMaps[dmap].xoff);
5398 }
5399 void zmap::goto_mapscr(int map, int scr)
5400 {
5401 auto new_cursor = cursor;
5402 new_cursor.map = map;
5403 new_cursor.setScreen(scr);
5404 setCursor(std::move(new_cursor));
5405 }
5406
5407 void zmap::dowarp(int32_t type, int32_t index)
5408 {
5409 set_warpback();
5410 if(type==0)
5411 {
5412
5413 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5414 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5415
5416 switch(screens[cursor.screen].tilewarptype[index])
5417 {
5418 case wtCAVE:
5419 case wtNOWARP:
5420 break;
5421
5422 default:
5423 goto_dmapscr(dmap, scr);
5424 break;
5425 }
5426 }
5427 else if(type==1)
5428 {
5429 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5430 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5431
5432 switch(screens[cursor.screen].sidewarptype[index])
5433 {
5434 case wtCAVE:
5435 case wtNOWARP:
5436 break;
5437
5438 default:
5439 goto_dmapscr(dmap, scr);
5440 break;
5441 }
5442 }
5443 }
5444
5445 extern int32_t prv_twon;
5446
5447 void zmap::prv_dowarp(int32_t type, int32_t index)
5448 {
5449 if(type==0)
5450 {
5451
5452 int32_t dmap=prvscr.tilewarpdmap[index];
5453 int32_t scr=prvscr.tilewarpscr[index];
5454
5455 switch(prvscr.tilewarptype[index])
5456 {
5457 case wtCAVE:
5458 case wtNOWARP:
5459 break;
5460
5461 default:
5462 //setCurrMap(DMaps[dmap].map);
5463 //setCurrScr(scr+DMaps[dmap].xoff);
5464 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5465 refresh_color();
5466 //prv_cmbcycle=0;
5467 break;
5468 }
5469 }
5470 else if(type==1)
5471 {
5472 int32_t dmap=prvscr.sidewarpdmap[index];
5473 int32_t scr=prvscr.sidewarpscr[index];
5474
5475 switch(prvscr.sidewarptype[index])
5476 {
5477 case wtCAVE:
5478 case wtNOWARP:
5479 break;
5480
5481 default:
5482 //setCurrMap(DMaps[dmap].map);
5483 //setCurrScr(scr+DMaps[dmap].xoff);
5484 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5485 refresh_color();
5486 //prv_cmbcycle=0;
5487 break;
5488 }
5489 }
5490
5491 if(prv_twon)
5492 {
5493 prv_time=get_prvscr()->timedwarptics;
5494 }
5495 }
5496
5497 void zmap::dowarp2(int32_t ring,int32_t index)
5498 {
5499 set_warpback();
5500 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5501 }
5502
5503 void zmap::set_warpback()
5504 {
5505 warpbackmap = cursor.map;
5506 warpbackscreen = cursor.screen;
5507 }
5508 bool zmap::has_warpback()
5509 {
5510 return warpbackmap && warpbackscreen
5511 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5512 }
5513 void zmap::warpback()
5514 {
5515 if(!has_warpback())
5516 return;
5517
5518 int m = cursor.map, s = cursor.screen;
5519 goto_mapscr(*warpbackmap, *warpbackscreen);
5520 warpbackmap = m;
5521 warpbackscreen = s;
5522 }
5523
5524 bool save_msgstrs(const char *path)
5525 {
5526 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5527
5528 if(!f)
5529 {
5530 return false;
5531 }
5532
5533 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5534 {
5535 pack_fclose(f);
5536 return true;
5537 }
5538
5539 pack_fclose(f);
5540 return false;
5541 }
5542
5543 1 bool save_strings_tsv(const char *path)
5544 {
5545 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5546
5547
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5548 {
5549 return false;
5550 }
5551
5552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5553 {
5554 1 pack_fclose(f);
5555 1 return true;
5556 }
5557
5558 pack_fclose(f);
5559 return false;
5560 1 }
5561
5562 bool save_msgstrs_text(const char *path)
5563 {
5564 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5565
5566 if(!f)
5567 {
5568 return false;
5569 }
5570
5571 if(writestrings_text(f)==0)
5572 {
5573 pack_fclose(f);
5574 return true;
5575 }
5576
5577 pack_fclose(f);
5578 return false;
5579 }
5580
5581 bool load_msgstrs(const char *path, int32_t startstring)
5582 {
5583 //these are here to bypass compiler warnings about unused arguments
5584 startstring=startstring;
5585
5586 dword section_id;
5587 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5588
5589 if(!f)
5590 {
5591 return false;
5592 }
5593
5594 if(!p_mgetl(&section_id,f))
5595 {
5596 return false;
5597 }
5598
5599 if(section_id==ID_STRINGS)
5600 {
5601 if(readstrings(f, &header)==0)
5602 {
5603 pack_fclose(f);
5604 return true;
5605 }
5606 else
5607 {
5608 pack_fclose(f);
5609 return false;
5610 }
5611 }
5612
5613 pack_fclose(f);
5614 return false;
5615 }
5616
5617 bool load_strings_tsv(const char *path)
5618 {
5619 try
5620 {
5621 parse_strings_tsv(util::read_text_file(path));
5622 }
5623 catch (std::exception& ex)
5624 {
5625 InfoDialog("Import .tsv Error", ex.what()).show();
5626 return false;
5627 }
5628 return true;
5629 }
5630
5631 bool save_pals(const char *path)
5632 {
5633 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5634
5635 if(!f)
5636 {
5637 return false;
5638 }
5639
5640 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5641 {
5642 pack_fclose(f);
5643 return true;
5644 }
5645
5646 pack_fclose(f);
5647 return false;
5648 }
5649
5650 bool load_pals(const char *path, int32_t startcset)
5651 {
5652 dword section_id;
5653 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5654
5655 if(!f)
5656 {
5657 return false;
5658 }
5659
5660 if(!p_mgetl(&section_id,f))
5661 {
5662 return false;
5663 }
5664
5665 if(section_id==ID_CSETS)
5666 {
5667 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5668 {
5669 pack_fclose(f);
5670 loadlvlpal(Color);
5671 return true;
5672 }
5673 else
5674 {
5675 pack_fclose(f);
5676 return false;
5677 }
5678 }
5679
5680 return false;
5681 }
5682
5683 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5684 bool save_guys(const char *path)
5685 {
5686 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5687
5688 if(!f)
5689 {
5690 return false;
5691 }
5692
5693 /*
5694 int32_t id = ID_GUYS;
5695 if(!p_mputl(id,f))
5696 {
5697 return false;
5698 }
5699 */
5700
5701 zquestheader h;
5702 h.zelda_version = 0x250;
5703 h.build = 21;
5704
5705 if(writeguys(f, &h)==0)
5706 {
5707 pack_fclose(f);
5708 return true;
5709 }
5710
5711 pack_fclose(f);
5712 return false;
5713 }
5714
5715 bool load_guys(const char *path)
5716 {
5717 dword section_id;
5718 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5719
5720 if(!f)
5721 {
5722 return false;
5723 }
5724
5725 if(!p_mgetl(&section_id,f))
5726 {
5727 pack_fclose(f);
5728 return false;
5729 }
5730
5731 zquestheader h;
5732 h.zelda_version = 0x250;
5733 h.build = 21;
5734
5735 if(section_id==ID_GUYS)
5736 {
5737 if(readguys(f, &h)==0)
5738 {
5739 pack_fclose(f);
5740 return true;
5741 }
5742 }
5743
5744 pack_fclose(f);
5745 return false;
5746 }
5747
5748
5749 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5750 bool save_combo_alias(const char *path)
5751 {
5752 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5753
5754 if(!f)
5755 {
5756 return false;
5757 }
5758
5759 zquestheader h;
5760 h.zelda_version = 0x250;
5761 h.build = 21;
5762
5763 if(writecomboaliases(f, 0, 0)==0)
5764 {
5765 pack_fclose(f);
5766 return true;
5767 }
5768
5769 pack_fclose(f);
5770 return false;
5771 }
5772
5773 bool load_combo_alias(const char *path)
5774 {
5775 dword section_id;
5776 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5777
5778 if(!f)
5779 {
5780 return false;
5781 }
5782
5783 if(!p_mgetl(&section_id,f))
5784 {
5785 pack_fclose(f);
5786 return false;
5787 }
5788
5789 zquestheader h;
5790 h.zelda_version = 0x250;
5791 h.build = 21;
5792
5793 if(section_id==ID_COMBOALIASES)
5794 {
5795 if(readcomboaliases(f, &h, 0, 0)==0)
5796 {
5797 pack_fclose(f);
5798 return true;
5799 }
5800 }
5801
5802 pack_fclose(f);
5803 return false;
5804 }
5805
5806 bool load_zgp(const char *path)
5807 {
5808 dword section_id;
5809 word section_version;
5810 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5811
5812 if(!f)
5813 return false;
5814
5815 if(!p_mgetl(&section_id,f))
5816 {
5817 pack_fclose(f);
5818 return false;
5819 }
5820
5821 if(section_id!=ID_GRAPHICSPACK)
5822 {
5823 pack_fclose(f);
5824 return false;
5825 }
5826
5827 //section version info
5828 if(!p_igetw(&section_version,f))
5829 {
5830 return 2;
5831 }
5832
5833 if(!read_deprecated_section_cversion(f))
5834 {
5835 return 3;
5836 }
5837
5838 //tiles
5839 if(!p_mgetl(&section_id,f))
5840 {
5841 pack_fclose(f);
5842 return false;
5843 }
5844
5845 if(section_id==ID_TILES)
5846 {
5847 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5848 {
5849 pack_fclose(f);
5850 init_tiles(true, &header);
5851 return false;
5852 }
5853 }
5854 else
5855 {
5856 pack_fclose(f);
5857 return false;
5858 }
5859
5860 //combos
5861 if(!p_mgetl(&section_id,f))
5862 {
5863 pack_fclose(f);
5864 return false;
5865 }
5866
5867 if(section_id==ID_COMBOS)
5868 {
5869 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5870 {
5871 pack_fclose(f);
5872 return false;
5873 }
5874 }
5875 else
5876 {
5877 pack_fclose(f);
5878 return false;
5879 }
5880
5881 //palettes
5882 if(!p_mgetl(&section_id,f))
5883 {
5884 pack_fclose(f);
5885 return false;
5886 }
5887
5888 if(section_id==ID_CSETS)
5889 {
5890 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5891 {
5892 pack_fclose(f);
5893 return false;
5894 }
5895 }
5896 else
5897 {
5898 pack_fclose(f);
5899 return false;
5900 }
5901
5902 //items
5903 if(!p_mgetl(&section_id,f))
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 if(section_id==ID_ITEMS)
5910 {
5911 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5912 {
5913 pack_fclose(f);
5914 return false;
5915 }
5916 }
5917 else
5918 {
5919 pack_fclose(f);
5920 return false;
5921 }
5922
5923 //weapons
5924 if(!p_mgetl(&section_id,f))
5925 {
5926 pack_fclose(f);
5927 return false;
5928 }
5929
5930 if(section_id==ID_WEAPONS)
5931 {
5932 if(readweapons(f, &header)!=0)
5933 {
5934 pack_fclose(f);
5935 return false;
5936 }
5937 }
5938 else
5939 {
5940 pack_fclose(f);
5941 return false;
5942 }
5943
5944 //read the triforce pieces info and make sure it worked
5945 //really do this?
5946
5947 //read the game icons info and make sure it worked
5948 if(!p_mgetl(&section_id,f))
5949 {
5950 pack_fclose(f);
5951 return false;
5952 }
5953
5954 if(section_id==ID_ICONS)
5955 {
5956 if(readgameicons(f, &header, &QMisc)!=0)
5957 {
5958 pack_fclose(f);
5959 return false;
5960 }
5961 }
5962 else
5963 {
5964 pack_fclose(f);
5965 return false;
5966 }
5967
5968 //read the misc colors info and map styles info and make sure it worked
5969 if(!p_mgetl(&section_id,f))
5970 {
5971 pack_fclose(f);
5972 return false;
5973 }
5974
5975 if(section_id==ID_COLORS)
5976 {
5977 if(readmisccolors(f, &header, &QMisc)!=0)
5978 {
5979 pack_fclose(f);
5980 return false;
5981 }
5982 }
5983 else
5984 {
5985 pack_fclose(f);
5986 return false;
5987 }
5988
5989 //read the door combo sets and make sure it worked
5990 if(!p_mgetl(&section_id,f))
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995
5996 if(section_id==ID_DOORS)
5997 {
5998 if(readdoorcombosets(f, &header)!=0)
5999 {
6000 pack_fclose(f);
6001 return false;
6002 }
6003 }
6004 else
6005 {
6006 pack_fclose(f);
6007 return false;
6008 }
6009
6010 //read the template screens and make sure it worked
6011 //really do this?
6012
6013 //yay! it worked! close the file and say everything was ok.
6014 loadlvlpal(Color);
6015 setup_combo_animations();
6016 setup_combo_animations2();
6017 pack_fclose(f);
6018 return true;
6019 }
6020
6021 bool save_zgp(const char *path)
6022 {
6023 reset_combo_animations();
6024 reset_combo_animations2();
6025
6026 //open the file
6027 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6028
6029 if(!f)
6030 return false;
6031
6032 dword section_id=ID_GRAPHICSPACK;
6033 dword section_version=V_GRAPHICSPACK;
6034
6035 //section id
6036 if(!p_mputl(section_id,f))
6037 {
6038 return 1;
6039 }
6040
6041 //section version info
6042 if(!p_iputw(section_version,f))
6043 {
6044 return 2;
6045 }
6046
6047 if(!write_deprecated_section_cversion(section_version,f))
6048 {
6049 return 3;
6050 }
6051
6052 //tiles
6053 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6054 {
6055 pack_fclose(f);
6056 return false;
6057 }
6058
6059 //combos
6060 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6061 {
6062 pack_fclose(f);
6063 return false;
6064 }
6065
6066 //palettes
6067 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6068 {
6069 pack_fclose(f);
6070 return false;
6071 }
6072
6073 //items
6074 if(writeitems(f, &header)!=0)
6075 {
6076 pack_fclose(f);
6077 return false;
6078 }
6079
6080 //weapons
6081 if(writeweapons(f, &header)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086
6087 //write the triforce pieces info and make sure it worked
6088 //really do this?
6089
6090 //write the game icons info and make sure it worked
6091 if(writegameicons(f, &header)!=0)
6092 {
6093 pack_fclose(f);
6094 return false;
6095 }
6096
6097 //write the misc colors info and map styles info and make sure it worked
6098 if(writemisccolors(f, &header)!=0)
6099 {
6100 pack_fclose(f);
6101 return false;
6102 }
6103
6104 //write the door combo sets and make sure it worked
6105 if(writedoorcombosets(f, &header)!=0)
6106 {
6107 pack_fclose(f);
6108 return false;
6109 }
6110
6111 //write the template screens and make sure it worked
6112 //really do this?
6113
6114 pack_fclose(f);
6115 return true;
6116 }
6117
6118 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6119 {
6120 //open the file
6121 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6122
6123 if(!f)
6124 return false;
6125
6126 dword section_id=ID_SUBSCREEN;
6127 dword s_version=V_SUBSCREEN;
6128
6129 if(!p_mputl(section_id,f))
6130 {
6131 pack_fclose(f);
6132 return false;
6133 }
6134
6135 if(!p_iputw(s_version,f))
6136 {
6137 pack_fclose(f);
6138 return false;
6139 }
6140
6141 if(!write_deprecated_section_cversion(s_version,f))
6142 {
6143 pack_fclose(f);
6144 return false;
6145 }
6146
6147 if(savefrom.write(f))
6148 {
6149 pack_fclose(f);
6150 return false;
6151 }
6152
6153 pack_fclose(f);
6154 return true;
6155 }
6156
6157 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6158 {
6159 //open the file
6160 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6161
6162 if(!f)
6163 return false;
6164
6165 dword section_id;
6166 dword s_version;
6167
6168 if(!p_mgetl(&section_id,f))
6169 {
6170 pack_fclose(f);
6171 return false;
6172 }
6173
6174 if(section_id!=ID_SUBSCREEN)
6175 {
6176 pack_fclose(f);
6177 return false;
6178 }
6179
6180 if(!p_igetw(&s_version,f))
6181 {
6182 pack_fclose(f);
6183 return false;
6184 }
6185
6186 if (s_version > V_SUBSCREEN)
6187 return qe_version;
6188
6189 if(!read_deprecated_section_cversion(f))
6190 {
6191 pack_fclose(f);
6192 return false;
6193 }
6194
6195 if(s_version < 8)
6196 {
6197 subscreen_group g;
6198 memset(&g,0,sizeof(subscreen_group));
6199 if(read_one_old_subscreen(f,&g,s_version)!=0)
6200 {
6201 pack_fclose(f);
6202 return false;
6203 }
6204 if(g.ss_type != loadto.sub_type)
6205 {
6206 pack_fclose(f);
6207 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6208 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6209 return false;
6210 }
6211 loadto.clear();
6212 if(g.objects[0].type != ssoNULL)
6213 loadto.load_old(g);
6214 }
6215 else
6216 {
6217 ZCSubscreen tmp = ZCSubscreen();
6218 if (tmp.read(f, s_version))
6219 {
6220 pack_fclose(f);
6221 return false;
6222 }
6223 if(tmp.sub_type != loadto.sub_type)
6224 {
6225 pack_fclose(f);
6226 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6227 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6228 return false;
6229 }
6230 loadto.clear();
6231 loadto = tmp;
6232 }
6233
6234 pack_fclose(f);
6235 return true;
6236 }
6237
6238 bool setMapCount2(int32_t c)
6239 {
6240 int32_t oldmapcount=map_count;
6241 int32_t cur_map=Map.getCurrMap();
6242
6243 bound(c,1,MAXMAPS);
6244 map_count=c;
6245
6246 try
6247 {
6248 TheMaps.resize(c*MAPSCRS);
6249 Map.force_refr_pointer();
6250 map_infos.resize(c);
6251 }
6252 catch(...)
6253 {
6254 displayinfo("Error","Failed to change map count.");
6255 return false;
6256 }
6257
6258 bound(cur_map,0,c-1);
6259 if(map_count>oldmapcount)
6260 {
6261 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6262 {
6263 // copy the default palette to the new maps
6264 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6265
6266 Map.setCurrMap(mc);
6267 for(int32_t ms=0; ms<MAPSCRS; ms++)
6268 Map.clearscr(ms);
6269 }
6270 Map.setCurrMap(cur_map);
6271 }
6272 else
6273 {
6274 Map.setCurrMap(cur_map);
6275 if(!layers_valid(Map.CurrScr()))
6276 fix_layers(Map.CurrScr(), false);
6277
6278 for(int32_t i=0; i<MAXDMAPS; i++)
6279 {
6280 if(DMaps[i].map>=map_count)
6281 {
6282 DMaps[i].map=map_count-1;
6283 }
6284 }
6285 }
6286
6287 return true;
6288 }
6289
6290 extern BITMAP *bmap;
6291
6292 static bool loading_file_new = false;
6293 int32_t init_quest(std::string tileset_path)
6294 {
6295 if (tileset_path.empty())
6296 tileset_path = DEFAULT_TILESET;
6297
6298 loading_file_new = true;
6299 load_quest(tileset_path.c_str());
6300 loading_file_new = false;
6301
6302 set_window_title("ZC Editor - Untitled Quest");
6303 zinit.last_map = 0;
6304 zinit.last_screen = 0;
6305
6306 if(bmap != NULL)
6307 {
6308 destroy_bitmap(bmap);
6309 bmap=NULL;
6310 }
6311
6312 return 0;
6313 }
6314
6315 void set_questpwd(std::string_view pwd, bool use_keyfile)
6316 {
6317 header.use_keyfile=use_keyfile;
6318
6319 // string_view actually has some quirks that make it less than ideal here.
6320 // It'd probably be best to replace it, but this works for now.
6321 memset(header.password, 0, 256);
6322 strcpy(header.password, pwd.data());
6323 header.dirty_password=true;
6324
6325 cvs_MD5Context ctx;
6326 cvs_MD5Init(&ctx);
6327 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6328 cvs_MD5Final(header.pwd_hash, &ctx);
6329 }
6330
6331
6332 bool is_null_pwd_hash(uint8_t *pwd_hash)
6333 {
6334 cvs_MD5Context ctx;
6335 uint8_t md5sum[16];
6336 char pwd[2]="";
6337
6338 cvs_MD5Init(&ctx);
6339 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6340 cvs_MD5Final(md5sum, &ctx);
6341
6342 return (memcmp(md5sum,pwd_hash,16)==0);
6343 }
6344
6345 static DIALOG pwd_dlg[] =
6346 {
6347 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6348 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6349 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6350 // 2 (filename)
6351 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6352 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6353 // 4 (challenge hash)
6354 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6355 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6356 // 6 (password)
6357 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6358 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6359 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6360 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6361 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6362 };
6363
6364 int32_t reverse_string(char* str)
6365 {
6366
6367 if(NULL==str)
6368 {
6369 return -1; //no string
6370 }
6371
6372 int32_t l=(int32_t)strlen(str)-1; //get the string length
6373
6374 if(1==l)
6375 {
6376 return 1;
6377 }
6378
6379 char c;
6380
6381 for(int32_t x=0; x < l; x++,l--)
6382 {
6383 c = str[x];
6384 str[x] = str[l];
6385 str[l] = c;
6386 }
6387
6388 return 0;
6389 }
6390
6391 #ifdef __GNUC__
6392 #pragma GCC diagnostic push
6393 #pragma GCC diagnostic ignored "-Wunreachable-code"
6394 #endif
6395
6396 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6397 {
6398
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6399 11 return 1;
6400
6401 #ifdef __EMSCRIPTEN__
6402 return 1;
6403 #endif
6404
6405 //Protection against compiling a release version with password protection off.
6406 static bool passguard = false;
6407
6408 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6409 #define MUST_HAVE_PASSWORD
6410 passguard = true;
6411 #endif
6412
6413 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6414 #if (defined _MSC_VER || defined _NPASS)
6415 return 1;
6416 #endif
6417 #endif
6418 if(devpwd()) return 1;
6419
6420 char hash_string[33];
6421
6422 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6423 {
6424 return 1;
6425 }
6426
6427 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6428 return true;
6429
6430 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6431 pwd_dlg[2].dp=get_filename(filename);
6432 cvs_MD5Context ctx;
6433 uint8_t md5sum[16]={0};
6434 char response[33]="";
6435 char prompt[256]="";
6436
6437 memcpy(md5sum, hdr->pwd_hash, 16);
6438
6439 for(int32_t i=0; i<300; ++i)
6440 {
6441 for(int32_t j=0; j<16; ++j)
6442 {
6443 sprintf(response+j*2, "%02x", md5sum[j]);
6444 }
6445
6446 if(i&1)
6447 {
6448 reverse_string(response);
6449 }
6450
6451 if(i==149)
6452 {
6453 strcpy(hash_string, response);
6454 }
6455
6456 cvs_MD5Init(&ctx);
6457 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6458 cvs_MD5Final(md5sum, &ctx);
6459 }
6460
6461 pwd_dlg[4].dp=hash_string;
6462
6463 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6464 {
6465 sprintf(prompt,"%s",response);
6466 }
6467
6468 pwd_dlg[6].dp=prompt;
6469
6470 large_dialog(pwd_dlg);
6471
6472 int32_t cancel = do_zqdialog(pwd_dlg,6);
6473
6474 if(cancel == 8)
6475 return 2;
6476
6477 bool ret=check_questpwd(hdr, prompt);
6478
6479 if(!ret)
6480 {
6481 ret=(strcmp(response,prompt)==0);
6482 }
6483 return ret ? 1 : 0;
6484 11 }
6485
6486 void set_rules(byte* newrules);
6487 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6488 {
6489 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6490
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6491 {
6492
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
22 auto [ret, dsa] = alert_confirm_dsa("Apply New Bugfixes",
6493
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6494 "\nWould you like to apply them?"
6495 "\n(Applies 'Bugfix' rule template, un-checking compat rules)");
6496
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(ret)
6497 {
6498 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6499 }
6500
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(dsa)
6501 {
6502 zc_set_config("zquest",cfg,1);
6503 }
6504 11 }
6505 11 }
6506
6507 #ifdef __GNUC__
6508 #pragma GCC diagnostic pop
6509 #endif
6510
6511 11 int32_t load_quest(const char *filename, bool show_progress)
6512 {
6513 11 zq_freeze_all_rti();
6514
6515 char buf[2048];
6516 byte skip_flags[4];
6517
6518 11 dword tileset_flags = 0;
6519
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6520 {
6521 44 skip_flags[i]=0;
6522 44 }
6523
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6524 7634 set_qr(i,0);
6525 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6526
6527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6528 {
6529 init_quest(DEFAULT_TILESET);
6530 }
6531 else
6532 {
6533 11 int32_t accessret = quest_access(filename, &header);
6534
6535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6536 {
6537 init_quest(DEFAULT_TILESET);
6538
6539 if(accessret == 0)
6540 ret=qe_pwd;
6541 else
6542 ret=qe_cancel;
6543 }
6544 else
6545 {
6546 11 Map.clear();
6547
6548
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6549
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 int view_size = zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1);
6550
6551
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 Map.setCursor(MapCursor{
6552
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 .map = vbound(zinit.last_map, 0, map_count - 1),
6553 11 .screen = zinit.last_screen,
6554 11 .viewscr = zinit.last_screen,
6555 11 .size = view_size,
6556 });
6557
6558 extern int32_t current_mappage;
6559 11 current_mappage = 0;
6560 11 bool found_default = false;
6561
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6562 {
6563 83 auto &pg = map_page[q];
6564
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6565 {
6566 2 current_mappage = q;
6567 2 break;
6568 }
6569
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6570 72 continue;
6571 else
6572 {
6573 9 current_mappage = q;
6574 9 found_default = true;
6575 }
6576 9 }
6577
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6578
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6579
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6580 11 saved = true;
6581
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6582
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6583
6584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6585 {
6586 destroy_bitmap(bmap);
6587 bmap=NULL;
6588 }
6589
6590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6591 {
6592 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6593 set_window_title(buf);
6594 }
6595 11 }
6596 }
6597
6598 11 Map.ClearCommandHistory();
6599
6600
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6601 {
6602 void load_size_poses();
6603 load_size_poses();
6604 }
6605
6606 11 return ret;
6607 }
6608
6609 int32_t load_tileset(const char *filename, dword tsetflags)
6610 {
6611 zq_freeze_all_rti();
6612
6613 byte skip_flags[4];
6614
6615 for(int32_t i=0; i<4; ++i)
6616 skip_flags[i]=0;
6617 for(int32_t i=0; i<qr_MAX; i++)
6618 set_qr(i,0);
6619 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6620
6621 if(ret!=qe_OK)
6622 init_quest(DEFAULT_TILESET);
6623 else
6624 {
6625 if(tsetflags & TILESET_BUGFIX)
6626 applyRuleTemplate(ruletemplateFixCompat);
6627 if(tsetflags & TILESET_SCR_BUGFIX)
6628 applyRuleTemplate(ruletemplateFixZSCompat);
6629
6630 int32_t accessret = quest_access(filename, &header);
6631
6632 if(accessret != 1)
6633 {
6634 init_quest(DEFAULT_TILESET);
6635
6636 if(accessret == 0)
6637 ret=qe_pwd;
6638 else
6639 ret=qe_cancel;
6640 }
6641 else
6642 {
6643 Map.clear();
6644 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6645 Map.setCurrScr(zinit.last_screen);
6646 extern int32_t current_mappage;
6647 current_mappage = 0;
6648 bool found_default = false;
6649 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6650 {
6651 auto &pg = map_page[q];
6652 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6653 {
6654 current_mappage = q;
6655 break;
6656 }
6657 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6658 continue;
6659 else
6660 {
6661 current_mappage = q;
6662 found_default = true;
6663 }
6664 }
6665 refresh(rALL);
6666 refresh_pal();
6667 set_rules(quest_rules);
6668
6669 if(bmap != NULL)
6670 {
6671 destroy_bitmap(bmap);
6672 bmap=NULL;
6673 }
6674
6675 set_window_title("ZC Editor - Untitled Quest");
6676 first_save = false;
6677 mark_save_dirty();
6678 memset(filepath,0,255);
6679 memset(temppath,0,255);
6680 }
6681 }
6682
6683 Map.ClearCommandHistory();
6684
6685 return ret;
6686 }
6687
6688 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6689 {
6690
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6691 new_return(1);
6692
6693
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6694 new_return(2);
6695
6696
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6697 new_return(3);
6698
6699
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6700 new_return(4);
6701
6702
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6703 {
6704
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6705 new_return(5);
6706
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6707 new_return(6);
6708 1363650 }
6709
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6710 new_return(7);
6711
6712
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6713 new_return(8);
6714
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6715 new_return(9);
6716
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6717 new_return(10);
6718
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6719 new_return(11);
6720
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6721 new_return(12);
6722
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6723 new_return(13);
6724
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6725 new_return(14);
6726
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6727 new_return(15);
6728
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6729 new_return(16);
6730
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6731 new_return(17);
6732
6733
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6734 new_return(18);
6735
6736
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6737 new_return(19);
6738
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6740 new_return(20);
6741
6742
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6743 new_return(21);
6744
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6745 new_return(22);
6746
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6748 new_return(23);
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6750 new_return(24);
6751
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6752 new_return(25);
6753
6754
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6755 new_return(26);
6756
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6757
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6758 new_return(27);
6759
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6760 new_return(28);
6761 272730 return 0;
6762 }
6763
6764 130 bool write_midi(MIDI *m,PACKFILE *f)
6765 {
6766 int32_t c;
6767
6768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6769
6770
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6771 {
6772
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6773
6774
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6775 {
6776
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6777 return false;
6778 1264 }
6779 4160 }
6780
6781 130 return true;
6782 130 }
6783
6784 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6785 {
6786 9 dword section_id=ID_HEADER;
6787 9 dword section_version=V_HEADER;
6788 9 dword section_size=0;
6789
6790 //file header string
6791
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6792 {
6793 new_return(1);
6794 }
6795
6796 //section id
6797
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6798 {
6799 new_return(2);
6800 }
6801
6802 //section version info
6803
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6804 {
6805 new_return(3);
6806 }
6807
6808
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
6809 {
6810 new_return(4);
6811 }
6812
6813
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6814 {
6815 18 fake_pack_writing=(writecycle==0);
6816
6817 //section size
6818
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6819 {
6820 new_return(5);
6821 }
6822
6823 18 writesize=0;
6824
6825 //finally... section data
6826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6827 {
6828 new_return(6);
6829 }
6830
6831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6832 {
6833 new_return(7);
6834 }
6835
6836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6837 {
6838 new_return(8);
6839 }
6840
6841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(Header->internal,f))
6842 {
6843 new_return(10);
6844 }
6845
6846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(Header->quest_number,f))
6847 {
6848 new_return(11);
6849 }
6850
6851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->version,16,f))
6852 {
6853 new_return(12);
6854 }
6855
6856
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->minver,16,f))
6857 {
6858 new_return(13);
6859 }
6860
6861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6862 {
6863 new_return(14);
6864 }
6865
6866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6867 {
6868 new_return(15);
6869 }
6870
6871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(Header->use_keyfile,f))
6872 {
6873 new_return(16);
6874 }
6875
6876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6877 {
6878 new_return(17);
6879 }
6880
6881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6882 {
6883 new_return(19);
6884 }
6885
6886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(0,f)) //why are we doing this?
6887 //this is for map count, it seems. -Z
6888 {
6889 new_return(20);
6890 }
6891
6892 18 auto version = getVersion();
6893
6894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.major,f))
6895 {
6896 new_return(21);
6897 }
6898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.minor,f))
6899 {
6900 new_return(22);
6901 }
6902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputl(version.patch,f))
6903 {
6904 new_return(23);
6905 }
6906 // Fourth component is deprecated.
6907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6908 {
6909 new_return(24);
6910 }
6911
6912 // Numerous prerelease stages is deprecated.
6913
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6914 {
6915 new_return(25);
6916 }
6917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6918 {
6919 new_return(26);
6920 }
6921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6922 {
6923 new_return(27);
6924 }
6925
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6926 {
6927 new_return(28);
6928 }
6929
6930
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6931 {
6932 new_return(29);
6933 }
6934
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6935 {
6936 new_return(30);
6937 }
6938
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6939 {
6940 new_return(31);
6941 }
6942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6943 {
6944 new_return(32);
6945 }
6946
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6947 {
6948 new_return(33);
6949 }
6950
6951 // This is no longer set to anything.
6952 const char* tempsig[256];
6953 18 memset(tempsig, 0, 256);
6954
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6955 {
6956 new_return(34);
6957 }
6958
6959 char tempcompilersig[256];
6960 18 memset(tempcompilersig, 0, 256);
6961 18 strcpy(tempcompilersig, COMPILER_NAME);
6962
6963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6964 {
6965 new_return(35);
6966 }
6967
6968 char tempcompilerversion[256];
6969 18 memset(tempcompilerversion, 0, 256);
6970 #ifdef _MSC_VER
6971 zc_itoa(_MSC_VER,tempcompilerversion,10);
6972 #else
6973 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6974 #endif
6975
6976
6977
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6978 {
6979 new_return(36);
6980 }
6981
6982
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6983 {
6984 new_return(37);
6985 }
6986
6987 // V_ZC_COMPILERSIG - a deprecated version field.
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6989 {
6990 new_return(38);
6991 }
6992 #ifdef _MSC_VER
6993 if(!p_iputl((_MSC_VER / 100),f))
6994 {
6995 new_return(39);
6996 }
6997 #else
6998
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
6999 {
7000 new_return(39);
7001 }
7002 #endif
7003
7004
7005
7006 #ifdef _MSC_VER
7007 if(!p_iputl((_MSC_VER % 100),f))
7008 {
7009 new_return(41);
7010 }
7011 #else
7012
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7013 {
7014 new_return(41);
7015 }
7016 #endif
7017
7018 #ifdef _MSC_VER
7019 # if _MSC_VER >= 1400
7020 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7021 {
7022 new_return(40);
7023 }
7024 # else
7025 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7026 {
7027 new_return(40);
7028 }
7029 #endif
7030 #else
7031
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7032 {
7033 new_return(40);
7034 }
7035 #endif
7036
7037 #ifdef _MSC_VER
7038 if(!p_iputl((_MSC_BUILD),f))
7039 {
7040 new_return(42);
7041 }
7042 #else
7043
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7044 {
7045 new_return(42);
7046 }
7047 #endif
7048
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7049 {
7050 new_return(43);
7051 }
7052
7053 // Modules were removed (replaced by zinfo).
7054 char tempmodulename[1024];
7055 18 memset(tempmodulename, 0, 1024);
7056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7057 {
7058 new_return(44);
7059 }
7060
7061 char tempdate[256];
7062 18 memset(tempdate, 0, 256);
7063 18 strcpy(tempdate, __DATE__);
7064
7065
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7066 {
7067 new_return(45);
7068 }
7069 char temptime[256];
7070 18 memset(temptime, 0, 256);
7071 18 strcpy(temptime, __TIME__);
7072
7073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7074 {
7075 new_return(46);
7076 }
7077
7078
7079 char temptimezone[6];
7080 18 memset(temptimezone, 0, 6);
7081 18 strcpy(temptimezone, __TIMEZONE__);
7082
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7083 {
7084 new_return(47);
7085 }
7086
7087
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7088 {
7089 new_return(48);
7090 }
7091
7092
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7093 {
7094 new_return(49);
7095 }
7096
7097
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7098 {
7099 new_return(50);
7100 }
7101
7102
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7103 {
7104 9 section_size=writesize;
7105 9 }
7106 18 }
7107
7108
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7109 {
7110 displayinfo("Error: writeheader()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7111 }
7112
7113 9 new_return(0);
7114 }
7115
7116 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7117 {
7118 //these are here to bypass compiler warnings about unused arguments
7119 9 Header=Header;
7120
7121 9 dword section_id=ID_RULES;
7122 9 dword section_version=V_RULES;
7123 9 dword section_size=0;
7124
7125 //section id
7126
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7127 {
7128 new_return(1);
7129 }
7130
7131 //section version info
7132
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7133 {
7134 new_return(2);
7135 }
7136
7137
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7138 {
7139 new_return(3);
7140 }
7141
7142
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputl(V_COMPATRULE,f))
7143 {
7144 new_return(6);
7145 }
7146
7147
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7148 {
7149 18 fake_pack_writing=(writecycle==0);
7150
7151 //section size
7152
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7153 {
7154 new_return(4);
7155 }
7156
7157 18 writesize=0;
7158
7159 //finally... section data
7160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7161 {
7162 new_return(5);
7163 }
7164
7165
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7166 {
7167 9 section_size=writesize;
7168 9 }
7169 18 }
7170
7171
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7172 {
7173 displayinfo("Error: writerules()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7174 }
7175
7176 9 new_return(0);
7177 }
7178
7179
7180 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7181 {
7182 //these are here to bypass compiler warnings about unused arguments
7183 9 Header=Header;
7184
7185 9 dword section_id=ID_DOORS;
7186 9 dword section_version=V_DOORS;
7187 9 dword section_size=0;
7188
7189 //section id
7190
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7191 {
7192 new_return(1);
7193 }
7194
7195 //section version info
7196
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7197 {
7198 new_return(2);
7199 }
7200
7201
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7202 {
7203 new_return(3);
7204 }
7205
7206
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7207 {
7208 18 fake_pack_writing=(writecycle==0);
7209
7210 //section size
7211
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7212 {
7213 new_return(4);
7214 }
7215
7216 18 writesize=0;
7217
7218 //finally... section data
7219
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7220 {
7221 new_return(5);
7222 }
7223
7224
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 320 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7225 {
7226 //name
7227 char name[21];
7228 320 memset(name, 21, (char)0);
7229 320 strcpy(name, DoorComboSetNames[i].c_str());
7230
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7231 {
7232 new_return(6);
7233 }
7234
7235 //up door
7236
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7237 {
7238
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7239 {
7240
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7241 {
7242 new_return(7);
7243 }
7244 11520 }
7245 2880 }
7246
7247
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7248 {
7249
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7250 {
7251
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7252 {
7253 new_return(8);
7254 }
7255 11520 }
7256 2880 }
7257
7258 //down door
7259
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7260 {
7261
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7262 {
7263
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7264 {
7265 new_return(9);
7266 }
7267 11520 }
7268 2880 }
7269
7270
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7271 {
7272
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7273 {
7274
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7275 {
7276 new_return(10);
7277 }
7278 11520 }
7279 2880 }
7280
7281
7282 //left door
7283
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7284 {
7285
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7286 {
7287
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7288
7289 {
7290 new_return(11);
7291 }
7292 17280 }
7293 2880 }
7294
7295
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7296 {
7297
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7298 {
7299
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7300 {
7301 new_return(12);
7302 }
7303 17280 }
7304 2880 }
7305
7306 //right door
7307
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7308 {
7309
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7310 {
7311
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7312 {
7313 new_return(13);
7314 }
7315 17280 }
7316 2880 }
7317
7318
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7319 {
7320
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7321 {
7322
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7323 {
7324 new_return(14);
7325 }
7326 17280 }
7327 2880 }
7328
7329
7330 //up bomb rubble
7331
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7332 {
7333
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7334 {
7335 new_return(15);
7336 }
7337 640 }
7338
7339
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7340 {
7341
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7342 {
7343 new_return(16);
7344 }
7345 640 }
7346
7347 //down bomb rubble
7348
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7349 {
7350
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7351 {
7352 new_return(17);
7353 }
7354 640 }
7355
7356
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7357 {
7358
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7359 {
7360 new_return(18);
7361 }
7362 640 }
7363
7364 //left bomb rubble
7365
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7366 {
7367
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7368 {
7369 new_return(19);
7370 }
7371 960 }
7372
7373
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7374 {
7375
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7376 {
7377 new_return(20);
7378 }
7379 960 }
7380
7381 //right bomb rubble
7382
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7383 {
7384
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7385 {
7386 new_return(21);
7387 }
7388 960 }
7389
7390
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7391 {
7392
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7393 {
7394 new_return(22);
7395 }
7396 960 }
7397
7398 //walkthrough stuff
7399
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7400 {
7401
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7402 {
7403 new_return(23);
7404 }
7405 1280 }
7406
7407
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7408 {
7409
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7410 {
7411 new_return(24);
7412 }
7413 1280 }
7414
7415 //flags
7416
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 640 times.
960 for(int32_t j=0; j<2; j++)
7417 {
7418
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7419 {
7420 new_return(25);
7421 }
7422 640 }
7423 320 }
7424
7425
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7426 {
7427 9 section_size=writesize;
7428 9 }
7429 18 }
7430
7431
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7432 {
7433 displayinfo("Error: writedoorcombosets()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7434 }
7435
7436 9 new_return(0);
7437 }
7438
7439 9216 int32_t write_one_dmap(PACKFILE* f, int index)
7440 {
7441 9216 DMaps[index].validate_subscreens();
7442
7443
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].map,f))
7444 {
7445 new_return(6);
7446 }
7447
7448
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].level,f))
7449 {
7450 new_return(7);
7451 }
7452
7453
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].xoff,f))
7454 {
7455 new_return(8);
7456 }
7457
7458
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].compass,f))
7459 {
7460 new_return(9);
7461 }
7462
7463
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].color,f))
7464 {
7465 new_return(10);
7466 }
7467
7468
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].cont,f))
7469 {
7470 new_return(12);
7471 }
7472
7473
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].type,f))
7474 {
7475 new_return(13);
7476 }
7477
7478
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7479 {
7480
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[index].grid[j],f))
7481 {
7482 new_return(14);
7483 }
7484 73728 }
7485
7486
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].name,sizeof(DMaps[0].name)-1,f))
7487 {
7488 new_return(15);
7489 }
7490
7491
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[index].title,f))
7492 {
7493 new_return(16);
7494 }
7495
7496
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[index].intro,sizeof(DMaps[0].intro)-1,f))
7497 {
7498 new_return(17);
7499 }
7500
7501
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[0],f))
7502 {
7503 new_return(18);
7504 }
7505
7506
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[0],f))
7507 {
7508 new_return(19);
7509 }
7510
7511
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].minimap_tile[1],f))
7512 {
7513 new_return(20);
7514 }
7515
7516
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].minimap_cset[1],f))
7517 {
7518 new_return(21);
7519 }
7520
7521
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[0],f))
7522 {
7523 new_return(22);
7524 }
7525
7526
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[0],f))
7527 {
7528 new_return(23);
7529 }
7530
7531
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].largemap_tile[1],f))
7532 {
7533 new_return(24);
7534 }
7535
7536
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].largemap_cset[1],f))
7537 {
7538 new_return(25);
7539 }
7540
7541
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].active_subscreen,f))
7542 {
7543 new_return(26);
7544 }
7545
7546
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].passive_subscreen,f))
7547 {
7548 new_return(27);
7549 }
7550
7551 byte disabled[32];
7552 9216 memset(disabled,0,32);
7553
7554
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7555 {
7556
1/2
✓ Branch 0 taken 2359296 times.
✗ Branch 1 not taken.
2359296 if(DMaps[index].disableditems[j])
7557 {
7558 disabled[j/8] |= (1 << (j%8));
7559 }
7560 2359296 }
7561
7562
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7563 {
7564 new_return(28);
7565 }
7566
7567
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[index].flags,f))
7568 new_return(29);
7569
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].sideview,f))
7570 new_return(30);
7571
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].script,f))
7572 new_return(31);
7573
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7574
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].initD[q],f))
7575 new_return(32);
7576
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7577
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7578
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[index].initD_label[q][w],f))
7579 73728 new_return(33);
7580
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].active_sub_script,f))
7581 new_return(34);
7582
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].passive_sub_script,f))
7583 new_return(35);
7584
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7585
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].sub_initD[q],f))
7586 new_return(36);
7587
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7588
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7589
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].sub_initD_label[q][w],f))
7590 73728 new_return(37);
7591
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].onmap_script,f))
7592 new_return(38);
7593
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7594
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[index].onmap_initD[q],f))
7595 new_return(39);
7596
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7597
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7598
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[index].onmap_initD_label[q][w],f))
7599 73728 new_return(40);
7600
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].mirrorDMap,f))
7601 new_return(41);
7602
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].overlay_subscreen, f))
7603 new_return(46);
7604
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[index].intro_string_id, f))
7605 new_return(47);
7606
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[index].flags & dmfCUSTOM_GRAVITY)
7607 {
7608 if (!p_iputzf(DMaps[index].dmap_gravity, f))
7609 new_return(48);
7610 if (!p_iputzf(DMaps[index].dmap_terminal_v, f))
7611 new_return(49);
7612 }
7613
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].map_subscreen, f))
7614 new_return(50);
7615
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[index].floor, f))
7616 new_return(51);
7617
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[index].music, f))
7618 new_return(52);
7619 9216 return 0;
7620 }
7621 9 int32_t writedmaps(PACKFILE *f, word, word, word start_dmap, word max_dmaps)
7622 {
7623 9 word dmap_count=count_dmaps();
7624 9 dword section_id=ID_DMAPS;
7625 9 dword section_version=V_DMAPS;
7626 9 dword section_size=0;
7627
7628 //section id
7629
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7630 {
7631 new_return(1);
7632 }
7633
7634 //section version info
7635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7636 {
7637 new_return(2);
7638 }
7639
7640
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7641 {
7642 new_return(3);
7643 }
7644
7645
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7646 {
7647 18 fake_pack_writing=(writecycle==0);
7648
7649 //section size
7650
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7651 {
7652 new_return(4);
7653 }
7654
7655 18 writesize=0;
7656
7657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7659
7660 //finally... section data
7661
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7662 {
7663 new_return(5);
7664 }
7665
7666
7667
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7668 {
7669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (auto ret = write_one_dmap(f, i))
7670 return ret;
7671 9216 }
7672
7673
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7674 {
7675 9 section_size=writesize;
7676 9 }
7677 18 }
7678
7679
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7680 {
7681 displayinfo("Error: writedmaps()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7682 }
7683
7684 9 new_return(0);
7685 9 }
7686
7687 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7688 {
7689 //these are here to bypass compiler warnings about unused arguments
7690 9 Header=Header;
7691
7692 9 dword section_id=ID_COLORS;
7693 9 dword section_version=V_COLORS;
7694 9 dword section_size = 0;
7695
7696 //section id
7697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7698 {
7699 new_return(1);
7700 }
7701
7702
7703 //section version info
7704
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7705 {
7706 new_return(2);
7707 }
7708
7709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7710 {
7711 new_return(3);
7712 }
7713
7714
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7715 {
7716 18 fake_pack_writing=(writecycle==0);
7717
7718 //section size
7719
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7720 {
7721 new_return(4);
7722 }
7723
7724 18 writesize=0;
7725
7726
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7727 {
7728 new_return(5);
7729 }
7730
7731
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7732 {
7733 new_return(6);
7734 }
7735
7736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7737 {
7738 new_return(7);
7739 }
7740
7741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7742 {
7743 new_return(8);
7744 }
7745
7746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7747 {
7748 new_return(9);
7749 }
7750
7751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7752 {
7753 new_return(10);
7754 }
7755
7756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7757 {
7758 new_return(11);
7759 }
7760
7761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7762 {
7763 new_return(12);
7764 }
7765
7766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7767 {
7768 new_return(13);
7769 }
7770
7771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7772 {
7773 new_return(14);
7774 }
7775
7776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7777 {
7778 new_return(15);
7779 }
7780
7781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7782 {
7783 new_return(16);
7784 }
7785
7786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7787 {
7788 new_return(17);
7789 }
7790
7791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7792 {
7793 new_return(18);
7794 }
7795
7796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7797 {
7798 new_return(19);
7799 }
7800
7801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7802 {
7803 new_return(20);
7804 }
7805
7806
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7807 {
7808 new_return(21);
7809 }
7810
7811
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7812 {
7813 new_return(22);
7814 }
7815
7816
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7817 {
7818 new_return(23);
7819 }
7820
7821
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7822 {
7823 new_return(24);
7824 }
7825
7826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7827 {
7828 new_return(31);
7829 }
7830
7831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7832 {
7833 new_return(32);
7834 }
7835
7836
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7837 {
7838 new_return(33);
7839 }
7840
7841
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7842 {
7843 new_return(34);
7844 }
7845
7846
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7847 {
7848 new_return(35);
7849 }
7850
7851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7852 {
7853 new_return(36);
7854 }
7855
7856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7857 {
7858 new_return(37);
7859 }
7860
7861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7862 {
7863 new_return(38);
7864 }
7865
7866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7867 {
7868 new_return(39);
7869 }
7870
7871
7872
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7873 {
7874 9 section_size=writesize;
7875 9 }
7876 18 }
7877
7878
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7879 {
7880 displayinfo("Error: writemisccolors()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7881 }
7882
7883 9 new_return(0);
7884 }
7885
7886 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7887 {
7888 //these are here to bypass compiler warnings about unused arguments
7889 9 Header=Header;
7890
7891 9 dword section_id=ID_ICONS;
7892 9 dword section_version=V_ICONS;
7893 9 dword section_size = 0;
7894
7895 //section id
7896
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7897 {
7898 new_return(1);
7899 }
7900
7901 //section version info
7902
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7903 {
7904 new_return(2);
7905 }
7906
7907
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7908 {
7909 new_return(3);
7910 }
7911
7912
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7913 {
7914 18 fake_pack_writing=(writecycle==0);
7915
7916 //section size
7917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7918 {
7919 new_return(4);
7920 }
7921
7922 18 writesize=0;
7923
7924
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
7925 {
7926
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
7927 {
7928 new_return(5);
7929 }
7930 72 }
7931
7932
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7933 {
7934 9 section_size=writesize;
7935 9 }
7936 18 }
7937
7938
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7939 {
7940 displayinfo("Error: writegameicons()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
7941 }
7942
7943 9 new_return(0);
7944 }
7945
7946 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
7947 {
7948 //these are here to bypass compiler warnings about unused arguments
7949 9 Header=Header;
7950
7951 9 dword section_id=ID_MISC;
7952 9 dword section_version=V_MISC;
7953 9 word shops=count_shops(&QMisc);
7954 9 word infos=count_infos(&QMisc);
7955 9 word warprings=count_warprings(&QMisc);
7956 9 word triforces=8;
7957 9 dword section_size = 0;
7958
7959 //section id
7960
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7961 {
7962 new_return(1);
7963 }
7964
7965
7966 //section version info
7967
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7968 {
7969 new_return(2);
7970 }
7971
7972
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7973 {
7974 new_return(3);
7975 }
7976
7977
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7978 {
7979 18 fake_pack_writing=(writecycle==0);
7980
7981 //section size
7982
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7983 {
7984 new_return(4);
7985 }
7986
7987 18 writesize=0;
7988
7989 //shops
7990
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
7991 {
7992 new_return(5);
7993 }
7994
7995
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
7996 {
7997
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
7998 {
7999 new_return(6);
8000 }
8001
8002
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8003 {
8004
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8005 {
8006 new_return(7);
8007 }
8008 480 }
8009
8010
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8011 {
8012
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8013 {
8014 new_return(8);
8015 }
8016 480 }
8017
8018
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8019 {
8020
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8021 {
8022 new_return(9);
8023 }
8024 480 }
8025 160 }
8026
8027 //infos
8028
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8029 {
8030 new_return(10);
8031 }
8032
8033
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8034 {
8035
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8036 {
8037 new_return(11);
8038 }
8039
8040
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8041 {
8042
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8043 {
8044 new_return(12);
8045 }
8046 480 }
8047
8048
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8049 {
8050
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8051 {
8052 new_return(13);
8053 }
8054 480 }
8055 160 }
8056
8057 //warp rings
8058
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8059 {
8060 new_return(14);
8061 }
8062
8063
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8064 {
8065
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8066 {
8067
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8068 {
8069 new_return(15);
8070 }
8071 1872 }
8072
8073
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8074 {
8075
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8076 {
8077 new_return(16);
8078 }
8079 1872 }
8080
8081
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8082 {
8083 new_return(17);
8084 }
8085 208 }
8086
8087 //triforce pieces
8088
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8089 {
8090
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8091 {
8092 new_return(18);
8093 }
8094 144 }
8095
8096 //end string
8097
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8098 {
8099 new_return(19);
8100 }
8101
8102 //V_MISC >= 8
8103
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8104 {
8105
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 480 times.
640 for(int32_t j=0; j<3; j++)
8106 {
8107
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8108 {
8109 new_return(20);
8110 }
8111 480 }
8112 160 }
8113 //V_MISC >= 9
8114
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8115 {
8116
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8117 new_return(21);
8118 576 }
8119
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8120 {
8121
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 73728 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8122
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8123 new_return(22);
8124 576 }
8125 //V_MISC >= 11
8126
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8127 new_return(23);
8128
8129 //V_MISC >= 12
8130
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8131 {
8132
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8133 new_return(24);
8134 4608 }
8135
8136 //V_MISC >= 13
8137
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8138 {
8139 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8140
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8141 new_return(25);
8142
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8143 {
8144
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8145 new_return(25);
8146
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8147 new_return(25);
8148 3456 }
8149
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8150 new_return(25);
8151
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8152 new_return(25);
8153 1152 }
8154
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8155 {
8156 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8157
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8158 new_return(26);
8159
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8160 {
8161
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8162 new_return(26);
8163
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8164 new_return(26);
8165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_putc(bst->cset[j], f))
8166 new_return(26);
8167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->price[j], f))
8168 new_return(26);
8169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8170 new_return(26);
8171 13824 }
8172 4608 }
8173
8174 //V_MISC >= 14
8175
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8176 {
8177
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8178 new_return(27);
8179 4608 }
8180
8181 //V_MISC >= 17
8182 18 byte save_menu_count = 0;
8183
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(size_t q = 0; q < NUM_SAVE_MENUS; ++q)
8184
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if (!QMisc.save_menus[q].is_empty())
8185 save_menu_count = q+1;
8186
8187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(save_menu_count, f))
8188 new_return(28);
8189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(size_t q = 0; q < save_menu_count; ++q)
8190 {
8191 SaveMenu const& menu = QMisc.save_menus[q];
8192
8193 byte empty = menu.is_empty() ? 1 : 0;
8194
8195 if (!p_putc(empty, f))
8196 new_return(29);
8197 if (empty) continue;
8198
8199 if (!p_putcstr(menu.name, f))
8200 new_return(30);
8201
8202 if (!p_iputw(menu.flags, f))
8203 new_return(31);
8204
8205 if (!p_iputl(menu.cursor_tile, f))
8206 new_return(32);
8207
8208 if (!p_putc(menu.cursor_cset, f))
8209 new_return(33);
8210
8211 if (!p_putc(menu.cursor_sfx, f))
8212 new_return(34);
8213
8214 if (!p_putc(menu.choose_sfx, f))
8215 new_return(35);
8216
8217 if (!p_putc(menu.bg_color, f))
8218 new_return(36);
8219
8220 if (!p_putc(menu.hspace, f))
8221 new_return(37);
8222
8223 if (!p_putc(menu.vspace, f))
8224 new_return(38);
8225
8226 if (!p_putc(menu.opt_x, f))
8227 new_return(39);
8228
8229 if (!p_putc(menu.opt_y, f))
8230 new_return(40);
8231
8232 if (!p_putc(menu.text_align, f))
8233 new_return(41);
8234
8235 if (!p_putc(menu.textbox_align, f))
8236 new_return(42);
8237
8238 if (!p_iputw(menu.close_frames, f))
8239 new_return(43);
8240
8241 if (!p_putc(menu.close_flash_rate, f))
8242 new_return(44);
8243
8244 if (!p_iputw(menu.music, f))
8245 new_return(45);
8246
8247 if (!p_iputl(menu.bg_tile, f))
8248 new_return(46);
8249
8250 if (!p_putc(menu.bg_cset, f))
8251 new_return(47);
8252
8253 if (!p_putc(menu.bg_tw, f))
8254 new_return(48);
8255
8256 if (!p_putc(menu.bg_th, f))
8257 new_return(49);
8258
8259 byte opt_count = zc_min(menu.options.size(), MAX_SAVEMENU_OPTIONS);
8260 if (!p_putc(opt_count, f))
8261 new_return(50);
8262
8263 for (size_t q = 0; q < opt_count; ++q)
8264 {
8265 SaveMenuOption const& opt = menu.options[q];
8266
8267 if (!p_putcstr(opt.text, f))
8268 new_return(51);
8269
8270 if (!p_iputw(opt.flags, f))
8271 new_return(52);
8272
8273 if (!p_putc(opt.color, f))
8274 new_return(53);
8275
8276 if (!p_putc(opt.picked_color, f))
8277 new_return(54);
8278
8279 if (!p_iputl(opt.font, f))
8280 new_return(55);
8281
8282 if (!p_iputw(opt.gen_script, f))
8283 new_return(56);
8284 }
8285 }
8286
8287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p_putc(QMisc.savemenu_game_over, f))
8288 new_return(57);
8289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p_putc(QMisc.savemenu_f6, f))
8290 new_return(58);
8291
8292
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8293 {
8294 9 section_size=writesize;
8295 9 }
8296 18 }
8297
8298
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8299 {
8300 displayinfo("Error: writemisc()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8301 }
8302
8303 9 new_return(0);
8304 }
8305
8306 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8307 {
8308 //these are here to bypass compiler warnings about unused arguments
8309 9 Header=Header;
8310
8311 9 dword section_id=ID_ITEMS;
8312 9 dword section_version=V_ITEMS;
8313 // dword section_size=0;
8314 9 dword section_size = 0;
8315
8316 //section id
8317
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8318 {
8319 new_return(1);
8320 }
8321
8322 //section version info
8323
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8324 {
8325 new_return(2);
8326 }
8327
8328
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8329 {
8330 new_return(3);
8331 }
8332
8333
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8334 {
8335 18 fake_pack_writing=(writecycle==0);
8336
8337 //section size
8338
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8339 {
8340 new_return(4);
8341 }
8342
8343 18 writesize=0;
8344
8345 //finally... section data
8346
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8347 {
8348 new_return(5);
8349 }
8350
8351
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8352 {
8353
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8354 {
8355 new_return(5);
8356 }
8357 4608 }
8358
8359
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8360 {
8361
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8362 {
8363 new_return(6);
8364 }
8365
8366
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8367 {
8368 new_return(7);
8369 }
8370
8371
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8372 {
8373 new_return(8);
8374 }
8375
8376
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8377 {
8378 new_return(9);
8379 }
8380
8381
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8382 {
8383 new_return(10);
8384 }
8385
8386
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8387 {
8388 new_return(11);
8389 }
8390
8391
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8392 {
8393 new_return(12);
8394 }
8395
8396
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8397 {
8398 new_return(13);
8399 }
8400
8401
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8402 {
8403 new_return(14);
8404 }
8405
8406
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8407 {
8408 new_return(14);
8409 }
8410
8411
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8412 {
8413 new_return(15);
8414 }
8415
8416
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8417 {
8418 new_return(16);
8419 }
8420
8421
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8422 {
8423 new_return(17);
8424 }
8425
8426
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8427 {
8428 new_return(18);
8429 }
8430
8431
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8432 {
8433 new_return(19);
8434 }
8435
8436
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8437 {
8438 new_return(21);
8439 }
8440
8441
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8442 {
8443 new_return(22);
8444 }
8445
8446
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8447 {
8448 new_return(23);
8449 }
8450
8451
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8452 {
8453
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8454 {
8455 new_return(24);
8456 }
8457 36864 }
8458
8459
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8460 {
8461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8462 {
8463 new_return(25);
8464 }
8465 9216 }
8466
8467
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8468 {
8469 new_return(26);
8470 }
8471
8472
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8473 {
8474 new_return(27);
8475 }
8476
8477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8478 {
8479 new_return(28);
8480 }
8481
8482
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8483 {
8484 new_return(29);
8485 }
8486
8487
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8488 {
8489 new_return(30);
8490 }
8491
8492
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8493 {
8494 new_return(31);
8495 }
8496
8497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8498 {
8499 new_return(32);
8500 }
8501
8502
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8503 {
8504 new_return(33);
8505 }
8506
8507
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8508 {
8509 new_return(34);
8510 }
8511
8512
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8513 {
8514 new_return(35);
8515 }
8516
8517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8518 {
8519 new_return(36);
8520 }
8521
8522
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8523 {
8524 new_return(37);
8525 }
8526
8527
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8528 {
8529 new_return(38);
8530 }
8531
8532
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8533 {
8534
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8535 {
8536 new_return(39);
8537 }
8538 9216 }
8539
8540
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8541 {
8542 new_return(40);
8543 }
8544
8545
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8546 {
8547 new_return(41);
8548 }
8549
8550
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8551 {
8552 new_return(42);
8553 }
8554
8555
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8556 {
8557 new_return(43);
8558 }
8559
8560
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8561 {
8562 new_return(44);
8563 }
8564
8565
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8566 {
8567 new_return(45);
8568 }
8569
8570
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8571 {
8572 new_return(46);
8573 }
8574
8575
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8576 {
8577 new_return(47);
8578 }
8579
8580
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8581 {
8582 new_return(48);
8583 }
8584
8585
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8586 {
8587 new_return(48);
8588 }
8589
8590 //New itemdata vars -Z
8591 //! version 27
8592
8593
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8594 {
8595 new_return(51);
8596 }
8597
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8598 {
8599 new_return(52);
8600 }
8601
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8602
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8603 {
8604 new_return(53);
8605 }
8606 46080 }
8607 //version 28
8608
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8609 {
8610 new_return(54);
8611 }
8612
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8613 {
8614
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8615 {
8616 new_return(56);
8617 }
8618 9216 }
8619
8620
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8621 {
8622 new_return(57);
8623 }
8624
8625
8626
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8627 {
8628 new_return(58);
8629 }
8630
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8631 {
8632 new_return(59);
8633 }
8634
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8635 {
8636 new_return(60);
8637 }
8638
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8639 {
8640 new_return(61);
8641 }
8642
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8643 {
8644 new_return(62);
8645 }
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8647 {
8648 new_return(63);
8649 }
8650
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8651 {
8652 new_return(64);
8653 }
8654
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8655 {
8656 new_return(73);
8657 }
8658
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8659 {
8660
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8661 {
8662 new_return(74);
8663 }
8664 9216 }
8665
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8666 {
8667 new_return(75);
8668 }
8669
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8670 {
8671 new_return(76);
8672 }
8673
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8674 {
8675 new_return(77);
8676 }
8677
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8678 {
8679 new_return(81);
8680 }
8681
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8682 {
8683 new_return(82);
8684 }
8685
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8686 {
8687 new_return(83);
8688 }
8689
8690
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8691 {
8692
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8693 {
8694 new_return(84);
8695 }
8696 9216 }
8697
8698 //InitD[] labels
8699
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8700 {
8701
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8702 {
8703
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8704 {
8705 new_return(85);
8706 }
8707 2396160 }
8708
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8709 {
8710
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8711 {
8712 new_return(87);
8713 }
8714 2396160 }
8715
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8716 {
8717 new_return(88);
8718 }
8719 36864 }
8720
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8721 {
8722
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8723 {
8724 new_return(89);
8725 }
8726
8727 9216 }
8728
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8729 {
8730 new_return(90);
8731 }
8732
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8733 {
8734 new_return(91);
8735 }
8736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8737
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8738 new_return(92);
8739
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8740 new_return(95);
8741
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8742 new_return(96);
8743
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8744 new_return(97);
8745
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8746 return ret;
8747
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8748 new_return(98);
8749
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8750
8751
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8752 {
8753 9 section_size=writesize;
8754 9 }
8755 18 }
8756
8757
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8758 {
8759 displayinfo("Error: writeitems()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8760 }
8761
8762 9 new_return(0);
8763 9 }
8764
8765 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8766 {
8767 //these are here to bypass compiler warnings about unused arguments
8768 9 Header=Header;
8769
8770 9 dword section_id=ID_WEAPONS;
8771 9 dword section_version=V_WEAPONS;
8772 9 dword section_size = 0;
8773
8774 //section id
8775
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8776 {
8777 new_return(1);
8778 }
8779
8780 //section version info
8781
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8782 {
8783 new_return(2);
8784 }
8785
8786
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8787 {
8788 new_return(3);
8789 }
8790
8791
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8792 {
8793 18 fake_pack_writing=(writecycle==0);
8794
8795 //section size
8796
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8797 {
8798 new_return(4);
8799 }
8800
8801 18 writesize=0;
8802
8803 //finally... section data
8804
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8805 {
8806 new_return(5);
8807 }
8808
8809
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8810 {
8811
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8812 {
8813 new_return(5);
8814 }
8815 4608 }
8816
8817
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8818 {
8819
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8820 {
8821 new_return(7);
8822 }
8823
8824
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8825 {
8826 new_return(8);
8827 }
8828
8829
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8830 {
8831 new_return(9);
8832 }
8833
8834
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8835 {
8836 new_return(10);
8837 }
8838
8839
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8840 {
8841 new_return(11);
8842 }
8843
8844
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8845 {
8846 new_return(12);
8847 }
8848
8849
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8850 {
8851 new_return(12);
8852 }
8853 4608 }
8854
8855
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8856 {
8857 9 section_size=writesize;
8858 9 }
8859 18 }
8860
8861
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8862 {
8863 displayinfo("Error: writeweapons()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
8864 }
8865
8866 9 new_return(0);
8867 }
8868
8869 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8870 {
8871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8872 return qe_invalid;
8873
8874 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8875 12784 bool is_0x80_screen = j >= 0x80;
8876
8877
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8878 return qe_invalid;
8879
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8880 4404 return qe_OK;
8881 //Calculate what needs writing
8882 8380 uint32_t scr_has_flags = 0;
8883
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8884
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8885 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8886
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8887 446 scr_has_flags |= SCRHAS_ITEM;
8888
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8889 28 scr_has_flags |= SCRHAS_TWARP;
8890
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8891 {
8892
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8893
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8894
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8895 {
8896 176 scr_has_flags |= SCRHAS_TWARP;
8897 176 break;
8898 }
8899 32706 }
8900
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8901
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8902 36 scr_has_flags |= SCRHAS_SWARP;
8903
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8904 {
8905
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8906
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8907
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8908 {
8909 4270 scr_has_flags |= SCRHAS_SWARP;
8910 4270 break;
8911 }
8912 16298 }
8913
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8914 44 scr_has_flags |= SCRHAS_WARPRET;
8915
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8916 {
8917
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8918 {
8919 784 scr_has_flags |= SCRHAS_WARPRET;
8920 784 break;
8921 }
8922 30208 }
8923
8924
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8925 scr_has_flags |= SCRHAS_LAYERS;
8926
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8927 {
8928
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8929
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8930 {
8931 966 scr_has_flags |= SCRHAS_LAYERS;
8932 966 break;
8933 }
8934 44532 }
8935
8936
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8937 10 scr_has_flags |= SCRHAS_MAZE;
8938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8939 scr_has_flags |= SCRHAS_MAZE;
8940
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8941 {
8942
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8943 {
8944 scr_has_flags |= SCRHAS_MAZE;
8945 break;
8946 }
8947 33480 }
8948
8949
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8950
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8951
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8952 2968 scr_has_flags |= SCRHAS_D_S_U;
8953
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8954 {
8955
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8956 {
8957 5212 scr_has_flags |= SCRHAS_D_S_U;
8958 5212 break;
8959 }
8960 800 }
8961
8962
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8963
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8964
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8965
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8966
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8967
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8968 8380 scr_has_flags |= SCRHAS_FLAGS;
8969
8970
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8971 58 scr_has_flags |= SCRHAS_ENEMY;
8972
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8973 {
8974
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8975 {
8976 1014 scr_has_flags |= SCRHAS_ENEMY;
8977 1014 break;
8978 }
8979 73086 }
8980
8981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8982 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8983 8380 scr_has_flags |= SCRHAS_CARRY;
8984
8985
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8986 22 scr_has_flags |= SCRHAS_SCRIPT;
8987
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8988 {
8989
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8990 {
8991 scr_has_flags |= SCRHAS_SCRIPT;
8992 break;
8993 }
8994 66864 }
8995
8996
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8997 {
8998
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8999
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9000
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9001 {
9002 3076 scr_has_flags |= SCRHAS_SECRETS;
9003 3076 break;
9004 }
9005 680916 }
9006
9007
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9008 {
9009
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9010
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9011 {
9012 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9013 5360 break;
9014 }
9015 568532 }
9016
9017
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9018
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9019
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9020 || screen.timedwarptics || screen.music != -1
9021 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9022 8380 scr_has_flags |= SCRHAS_MISC;
9023
9024
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9025 return qe_invalid;
9026
9027 //Write stuff
9028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9029 {
9030
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9031 return qe_invalid;
9032
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9033 return qe_invalid;
9034
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9035 return qe_invalid;
9036
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9037 return qe_invalid;
9038
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9039 return qe_invalid;
9040
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9041 return qe_invalid;
9042
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9043 return qe_invalid;
9044 8380 }
9045
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9046 {
9047
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9048 return qe_invalid;
9049
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9050 return qe_invalid;
9051
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9052 return qe_invalid;
9053
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9054 return qe_invalid;
9055 446 }
9056
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9057 {
9058
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9059 return qe_invalid;
9060 4374 }
9061
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9062 {
9063
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9064 {
9065
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9066 return qe_invalid;
9067 816 }
9068
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9069 {
9070
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9071 return qe_invalid;
9072 816 }
9073
9074
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9075 {
9076
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9077 return qe_invalid;
9078 816 }
9079
9080
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9081 return qe_invalid;
9082 204 }
9083
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9084 {
9085
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9086 {
9087
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9088 return qe_invalid;
9089 17224 }
9090
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9091 {
9092
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9093 return qe_invalid;
9094 17224 }
9095
9096
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9097 {
9098
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9099 return qe_invalid;
9100 17224 }
9101
9102
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9103 return qe_invalid;
9104
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9105 return qe_invalid;
9106 4306 }
9107
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9108 {
9109
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9110 {
9111
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9112 return qe_invalid;
9113 3312 }
9114
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9115 {
9116
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9117 return qe_invalid;
9118 3312 }
9119
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9120 return qe_invalid;
9121
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9122 return qe_invalid;
9123 828 }
9124
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9125 {
9126
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9127 {
9128
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9129 return qe_invalid;
9130 5796 }
9131
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9132 {
9133
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9134 return qe_invalid;
9135 5796 }
9136
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9137 {
9138
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9139 return qe_invalid;
9140 5796 }
9141
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9142 return qe_invalid;
9143
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9144 return qe_invalid;
9145 966 }
9146
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9147 {
9148
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9149 {
9150
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9151 return qe_invalid;
9152 40 }
9153
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9154 return qe_invalid;
9155
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9156 return qe_invalid;
9157 10 }
9158
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9159 {
9160
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9161 return qe_invalid;
9162
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9163 {
9164
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9165 return qe_invalid;
9166 32720 }
9167
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9168 return qe_invalid;
9169
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9170 return qe_invalid;
9171
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9172 return qe_invalid;
9173
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9174 return qe_invalid;
9175 8180 }
9176
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9177 {
9178
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9179 return qe_invalid;
9180
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9181 return qe_invalid;
9182
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9183 return qe_invalid;
9184
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9185 return qe_invalid;
9186
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9187 return qe_invalid;
9188
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9189 return qe_invalid;
9190
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9191 return qe_invalid;
9192
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9193 return qe_invalid;
9194
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9195 return qe_invalid;
9196
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9197 return qe_invalid;
9198
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9199 return qe_invalid;
9200 1294 }
9201
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9202 {
9203
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9204 {
9205
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9206 return qe_invalid;
9207 10720 }
9208
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9209 return qe_invalid;
9210 1072 }
9211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9212 {
9213
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9220 return qe_invalid;
9221
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9222 return qe_invalid;
9223
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9224 return qe_invalid;
9225 8380 }
9226
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9227 {
9228
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9231 return qe_invalid;
9232
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9233 {
9234
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9235 return qe_invalid;
9236 176 }
9237 22 }
9238
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9239 {
9240
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9241 {
9242
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9243 return qe_invalid;
9244 393728 }
9245
9246
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9247 {
9248
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9249 return qe_invalid;
9250 393728 }
9251
9252
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9253 {
9254
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9255 return qe_invalid;
9256 393728 }
9257 3076 }
9258
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9259 {
9260
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9261 {
9262
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9263 return qe_invalid;
9264 943360 }
9265
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9266 {
9267
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9268 return qe_invalid;
9269 943360 }
9270
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9271 {
9272
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9273 return qe_invalid;
9274 943360 }
9275 5360 }
9276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9277 {
9278
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9279 return qe_invalid;
9280
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9281 return qe_invalid;
9282
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9283 return qe_invalid;
9284
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9285 return qe_invalid;
9286
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9287 return qe_invalid;
9288
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9289 return qe_invalid;
9290
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9291 return qe_invalid;
9292
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.music,f))
9293 return qe_invalid;
9294
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9295 return qe_invalid;
9296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9297 return qe_invalid;
9298
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9299 return qe_invalid;
9300 8380 }
9301
9302 8380 dword numffc = screen.numFFC();
9303
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9304 return qe_invalid;
9305
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9306 {
9307 245678 ffcdata const& tempffc = screen.ffcs[k];
9308
9309
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9310 return qe_invalid;
9311
9312
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9313 243364 continue;
9314
9315
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9316 return qe_invalid;
9317
9318
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9319 return qe_invalid;
9320
9321
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9322 return qe_invalid;
9323
9324
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9325 return qe_invalid;
9326
9327
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9328 return qe_invalid;
9329
9330
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9331 return qe_invalid;
9332
9333
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9334 return qe_invalid;
9335
9336
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9337 return qe_invalid;
9338
9339
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9340 return qe_invalid;
9341
9342
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9343 return qe_invalid;
9344
9345
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9346 return qe_invalid;
9347
9348
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9349 return qe_invalid;
9350
9351
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9352 return qe_invalid;
9353
9354
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9355 return qe_invalid;
9356
9357
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9358 return qe_invalid;
9359
9360
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9361 {
9362
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9363 return qe_invalid;
9364 18512 }
9365
9366
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9367 return qe_invalid;
9368 2314 }
9369
9370
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9371 return qe_invalid;
9372
9373
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9374 {
9375
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9376 return qe_invalid;
9377
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9378 return qe_invalid;
9379 6 }
9380
9381 8380 return qe_OK;
9382 12784 }
9383
9384 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9385 {
9386 9 dword section_id=ID_MAPS;
9387 9 dword section_version=V_MAPS;
9388 9 dword section_size = 0;
9389
9390 //section id
9391
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9392 {
9393 new_return(1);
9394 }
9395
9396 //section version info
9397
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9398 {
9399 new_return(2);
9400 }
9401
9402
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9403 {
9404 new_return(3);
9405 }
9406
9407
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9408 {
9409 18 fake_pack_writing=(writecycle==0);
9410
9411 //section size
9412
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9413 {
9414 new_return(4);
9415 }
9416
9417 18 writesize=0;
9418
9419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9420 {
9421 new_return(5);
9422 }
9423 18 map_infos.resize(map_count);
9424
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 100 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9425 {
9426 100 byte valid = 0;
9427
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9428 {
9429
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9430 break;
9431 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9432
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9433 {
9434 94 valid = 1;
9435 94 break;
9436 }
9437 1188 }
9438
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9439 {
9440 new_return(6);
9441 }
9442
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9443
9444 { //per-map info
9445 94 auto const& mapinf = map_infos[i];
9446
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9447 {
9448
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9449 new_return(7);
9450 564 }
9451
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9452 new_return(9);
9453
9454
9455
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9456 {
9457
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9458 {
9459
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9460 {
9461 new_return(8);
9462 }
9463 6016 }
9464 752 }
9465 }
9466
9467
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9468 12784 writemapscreen(f,i,j);
9469 94 }
9470
9471
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9472 {
9473 9 section_size=writesize;
9474 9 }
9475 18 }
9476
9477
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9478 {
9479 displayinfo("Error: writemaps()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
9480 }
9481
9482 9 new_return(0);
9483 }
9484
9485 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9486 {
9487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9488 return 22;
9489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9490 return 22;
9491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9492 return 23;
9493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9494 return 34;
9495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9496 return 35;
9497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9498 return 36;
9499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9500 return 37;
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9502 return 38;
9503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9504 return 39;
9505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9506 return 40;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9508 return 41;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9510 return 42;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9512 return 43;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9514 return 44;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9516 return 45;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9518 return 46;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9520 return 47;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9522 return 48;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9524 return 49;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9526 return 50;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9528 return 51;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9530 return 52;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9532 return 53;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9534 return 69;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9536 return 70;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9538 return 71;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9540 return 72;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9542 return 76;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9544 return 77;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9546 return 89;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9548 return 90;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9550 return 91;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9552 return 92;
9553
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9555 return 93;
9556
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9557 return 94;
9558
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9559 return 95;
9560
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9561 return 96;
9562
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9563 return 97;
9564
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9565 return 98;
9566
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9567 return 99;
9568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9569 return 100;
9570
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9571 return 101;
9572
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9573 return 102;
9574
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9575 return 103;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9577 return 104;
9578
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9579 return 105;
9580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9581 return 106;
9582
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9583 return 107;
9584
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9585 return 108;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9587 return 109;
9588
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9589 return 110;
9590
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9591 return 111;
9592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9593 return 112;
9594
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9595 return 113;
9596
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9597 return 114;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9599 return 115;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9601 return 116;
9602
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9603 return 117;
9604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9605 return 118;
9606
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9607 return 119;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9609 return 120;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9611 return 121;
9612
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9613 return 122;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9615 return 123;
9616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9617 return 124;
9618
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9619 return 125;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9621 return 126;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_state, f))
9623 return 127;
9624
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_state, f))
9625 return 128;
9626
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.req_screen_ex_state, f))
9627 return 129;
9628
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_screen_ex_state, f))
9629 return 130;
9630
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatemap, f))
9631 return 131;
9632
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trigstatescreen, f))
9633 return 132;
9634
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.play_music, f))
9635 return 133;
9636
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.set_music_refresh, f))
9637 return 134;
9638 460 return 0;
9639 460 }
9640 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9641 {
9642 //Check what needs writing
9643 258906 word combo_has_flags = 0;
9644
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 6161326 times.
6417042 for(auto q = 0; q < NUM_COMBO_ATTRIBUTES; ++q)
9645 {
9646
2/2
✓ Branch 0 taken 6158136 times.
✓ Branch 1 taken 3190 times.
6161326 if(tmp_cmb.c_attributes[q])
9647 {
9648 3190 combo_has_flags |= CHAS_ATTRIB;
9649 3190 break;
9650 }
9651 6158136 }
9652
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9653 460 combo_has_flags |= CHAS_TRIG;
9654
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9655 298 combo_has_flags |= CHAS_FLAG;
9656
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9657
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9658
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9659 28174 combo_has_flags |= CHAS_ANIM;
9660
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258900 times.
✓ Branch 3 taken 6 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9661 6 combo_has_flags |= CHAS_SCRIPT;
9662
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9663 {
9664
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9665 {
9666 combo_has_flags |= CHAS_SCRIPT;
9667 break;
9668 }
9669 2071200 }
9670
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9671
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9672 82514 combo_has_flags |= CHAS_BASIC;
9673
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9674
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9675
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9676
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9677
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9678
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9679
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9680 10 combo_has_flags |= CHAS_LIFT;
9681
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9682
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9683
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9684
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9685
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9686
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9687 258906 combo_has_flags |= CHAS_GENERAL;
9688
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9689 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9690
9691
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9692 {
9693 return 50;
9694 }
9695
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9696 //Write the combo
9697
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9698 {
9699
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9700 return 6;
9701
9702
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9703 return 7;
9704
9705
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9706 return 8;
9707
9708
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9709 return 9;
9710
9711
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9712 return 15;
9713
9714
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9715 return 10;
9716 82514 }
9717
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9718 {
9719 6 p_putcstr(tmp_cmb.label, f);
9720
9721
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9722 return 26;
9723
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9724
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9725 return 27;
9726 6 }
9727
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9728 {
9729
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9730 return 11;
9731
9732
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9733 return 12;
9734
9735
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9736 return 13;
9737
9738
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9739 return 14;
9740
9741
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9742 return 16;
9743
9744
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9745 return 18;
9746
9747
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9748 return 19;
9749 28174 }
9750
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9751 {
9752
1/2
✓ Branch 0 taken 3190 times.
✗ Branch 1 not taken.
3190 if (!p_iputw(NUM_COMBO_ATTRIBUTES, f))
9753 return 25;
9754
2/2
✓ Branch 0 taken 76560 times.
✓ Branch 1 taken 3190 times.
79750 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
9755
1/2
✓ Branch 0 taken 76560 times.
✗ Branch 1 not taken.
76560 if(!p_iputzf(tmp_cmb.c_attributes[q],f))
9756 return 20;
9757 3190 }
9758
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9759 {
9760
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9761 return 21;
9762
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9763 return 33;
9764 298 }
9765
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9766 {
9767
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9768
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9769 return 34;
9770
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9771 {
9772 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9773
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9774 460 }
9775
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9776 return 35;
9777 460 }
9778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9779 {
9780
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9781 return 54;
9782
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9783 return 55;
9784
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9785 return 56;
9786
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9787 return 57;
9788
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9789 return 58;
9790
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9791 return 59;
9792
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9793 return 60;
9794
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9795 return 61;
9796
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9797 return 62;
9798
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9799 return 63;
9800
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9801 return 64;
9802
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9803 return 65;
9804
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9805 return 66;
9806
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9807 return 67;
9808
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9809 return 68;
9810
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9811 return 78;
9812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9813 return ret;
9814 258906 }
9815
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9816 {
9817
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9818 return 73;
9819
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9820 return 74;
9821
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9822 return 75;
9823
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9824 return 79;
9825
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9826 return 80;
9827
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9828 return 81;
9829
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9830 return 82;
9831
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9832 return 83;
9833
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9834 return 84;
9835
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9836 return 85;
9837
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9838 return 86;
9839
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9840 return 87;
9841
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9842 return 88;
9843
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9844 return 89;
9845
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9846 return 90;
9847
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9848 return 91;
9849
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9850 return 92;
9851
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9852 return 93;
9853
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9854 return 94;
9855
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9856 return 95;
9857
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9858 return 96;
9859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9860 return 97;
9861
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9862 return 98;
9863 2200 }
9864
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9865 {
9866 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9867 return ret;
9868 }
9869 258906 return 0;
9870 258906 }
9871
9872 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9873 {
9874 //these are here to bypass compiler warnings about unused arguments
9875 9 version=version;
9876 9 build=build;
9877
9878 word combos_used;
9879 9 dword section_id=ID_COMBOS;
9880 9 dword section_version=V_COMBOS;
9881 // dword section_size=0;
9882 9 combos_used = count_combos()-start_combo;
9883
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9884
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9885 9 dword section_size = 0;
9886
9887 //section id
9888
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9889 {
9890 new_return(1);
9891 }
9892
9893 //section version info
9894
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9895 {
9896 new_return(2);
9897 }
9898
9899
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9900 {
9901 new_return(3);
9902 }
9903
9904
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9905 {
9906 18 fake_pack_writing=(writecycle==0);
9907
9908 //section size
9909
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9910 {
9911 new_return(4);
9912 }
9913
9914 18 writesize=0;
9915
9916 //finally... section data
9917 18 combos_used=count_combos()-start_combo;
9918
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9920
9921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9922 {
9923 new_return(5);
9924 }
9925
9926 18 size_t end_combo = start_combo+combos_used;
9927
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9928 {
9929 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9930
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9931 258906 }
9932
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9933 {
9934 9 section_size=writesize;
9935 9 }
9936 18 }
9937
9938
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9939 {
9940 displayinfo("Error: writecombos()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
9941 }
9942
9943 9 new_return(0);
9944 9 }
9945
9946 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9947 {
9948 //these are here to bypass compiler warnings about unused arguments
9949 9 version=version;
9950 9 build=build;
9951
9952 9 dword section_id=ID_COMBOALIASES;
9953 9 dword section_version=V_COMBOALIASES;
9954 9 dword section_size=0;
9955
9956 //section id
9957
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9958 {
9959 new_return(1);
9960 }
9961
9962 //section version info
9963
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9964 {
9965 new_return(2);
9966 }
9967
9968
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9969 {
9970 new_return(3);
9971 }
9972
9973
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9974 {
9975 18 fake_pack_writing=(writecycle==0);
9976
9977 //section size
9978
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9979 {
9980 new_return(4);
9981 }
9982
9983 18 writesize=0;
9984
9985 //finally... section data
9986
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9987 {
9988
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9989 {
9990 new_return(5);
9991 }
9992
9993
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9994 {
9995 new_return(6);
9996 }
9997
9998 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9999
10000
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
10001 {
10002 new_return(7);
10003 }
10004
10005
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
10006 {
10007 new_return(8);
10008 }
10009
10010
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10011 {
10012 new_return(9);
10013 }
10014
10015
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10016 {
10017
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10018 {
10019 new_return(10);
10020 }
10021 149596 }
10022
10023
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 149596 times.
297052 for(int32_t k=0; k<count; k++)
10024 {
10025
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10026 {
10027 new_return(11);
10028 }
10029 149596 }
10030 147456 }
10031
10032 //Combo pools!
10033 int16_t num_cpools;
10034
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10035 {
10036
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10037 {
10038 2 ++num_cpools;
10039 2 break;
10040 }
10041 147450 }
10042
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10043
10044
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10045 {
10046 new_return(12);
10047 }
10048
10049
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10050 {
10051 6 combo_pool const& pool = combo_pools[cp];
10052 6 int32_t num_combos = pool.combos.size();
10053
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10054 {
10055 new_return(13);
10056 }
10057
10058
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10059 {
10060 26 cpool_entry const& entry = pool.combos.at(q);
10061
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10062 {
10063 new_return(14);
10064 }
10065
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10066 {
10067 new_return(15);
10068 }
10069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if(!p_iputw(entry.quant,f))
10070 {
10071 new_return(16);
10072 }
10073 26 }
10074 6 }
10075
10076 //Autocombos!
10077 int16_t num_cautos;
10078
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10079 {
10080
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10081 {
10082 ++num_cautos;
10083 break;
10084 }
10085 147456 }
10086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10087
10088
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10089 {
10090 new_return(17);
10091 }
10092
10093
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10094 {
10095 combo_auto const& cauto = combo_autos[ca];
10096 if (!p_putc(cauto.getType(), f))
10097 {
10098 new_return(18);
10099 }
10100 if (!p_iputl(cauto.getIconDisplay(), f))
10101 {
10102 new_return(19);
10103 }
10104 if (!p_iputl(cauto.getEraseCombo(), f))
10105 {
10106 new_return(20);
10107 }
10108 if (!p_putc(cauto.getFlags(), f))
10109 {
10110 new_return(21);
10111 }
10112 if (!p_putc(cauto.getArg(), f))
10113 {
10114 new_return(22);
10115 }
10116 int32_t num_combos = cauto.combos.size();
10117 if (!p_iputl(num_combos, f))
10118 {
10119 new_return(23);
10120 }
10121
10122 for (auto q = 0; q < num_combos; ++q)
10123 {
10124 autocombo_entry const& entry = cauto.combos.at(q);
10125 if (!p_putc(entry.ctype, f))
10126 {
10127 new_return(24);
10128 }
10129 if (!p_iputl(entry.cid, f))
10130 {
10131 new_return(25);
10132 }
10133 }
10134 }
10135
10136
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10137 {
10138 9 section_size=writesize;
10139 9 }
10140 18 }
10141
10142
10143
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10144 {
10145 displayinfo("Error: writecomboaliases()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10146 }
10147
10148 9 new_return(0);
10149 }
10150
10151 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10152 {
10153 //these are here to bypass compiler warnings about unused arguments
10154 9 version=version;
10155 9 build=build;
10156 9 start_cset=start_cset;
10157 9 max_csets=max_csets;
10158
10159 9 dword section_id=ID_CSETS;
10160 9 dword section_version=V_CSETS;
10161 9 int32_t palcycles = count_palcycles(&QMisc);
10162 // int32_t palcyccount = count_palcycles(&QMisc);
10163 9 dword section_size = 0;
10164
10165 //section id
10166
10167
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10168 {
10169 new_return(1);
10170 }
10171
10172 //section version info
10173
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10174 {
10175 new_return(2);
10176 }
10177
10178
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10179 {
10180 new_return(3);
10181 }
10182
10183
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10184 {
10185 18 fake_pack_writing=(writecycle==0);
10186
10187 //section size
10188
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10189 {
10190 new_return(4);
10191 }
10192
10193 18 writesize=0;
10194
10195 //finally... section data
10196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10197 {
10198 new_return(5);
10199 }
10200
10201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10202 {
10203 new_return(6);
10204 }
10205
10206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(palcycles,f))
10207 {
10208 new_return(15);
10209 }
10210
10211
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10212 {
10213
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10214 {
10215
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10216 {
10217 new_return(16);
10218 }
10219 1650 }
10220
10221
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10222 {
10223
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10224 {
10225 new_return(17);
10226 }
10227 1650 }
10228
10229
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 1650 times.
2200 for(int32_t j=0; j<3; j++)
10230 {
10231
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10232 {
10233 new_return(18);
10234 }
10235 1650 }
10236 550 }
10237
10238
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10239 {
10240 9 section_size=writesize;
10241 9 }
10242 18 }
10243
10244
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10245 {
10246 displayinfo("Error: writecolordata()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10247 }
10248
10249 9 new_return(0);
10250 }
10251
10252 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10253 {
10254 //these are here to bypass compiler warnings about unused arguments
10255 9 version=version;
10256 9 build=build;
10257 9 start_msgstr=start_msgstr;
10258 9 max_msgstrs=max_msgstrs;
10259
10260 9 dword section_id=ID_STRINGS;
10261 9 dword section_version=V_STRINGS;
10262 9 dword section_size = 0;
10263
10264 //section id
10265
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10266 {
10267 new_return(1);
10268 }
10269
10270 //section version info
10271
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10272 {
10273 new_return(2);
10274 }
10275
10276
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10277 {
10278 new_return(3);
10279 }
10280
10281
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10282 {
10283 18 fake_pack_writing=(writecycle==0);
10284
10285 //section size
10286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10287 {
10288 new_return(4);
10289 }
10290
10291 18 writesize=0;
10292
10293 //finally... section data
10294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10295 {
10296 return qe_invalid;
10297 }
10298
10299
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10300 {
10301 836 MsgStrings[i].ensureAsciiEncoding();
10302 836 int32_t sz = MsgStrings[i].s.size();
10303
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10304
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10305 {
10306 return qe_invalid;
10307 }
10308
10309 836 char const* tmpstr = MsgStrings[i].s.c_str();
10310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10311 {
10312
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10313 {
10314 return qe_invalid;
10315 }
10316 836 }
10317
10318
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10319 {
10320 return qe_invalid;
10321 }
10322
10323
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10324 {
10325 return qe_invalid;
10326 }
10327
10328
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10329 {
10330 return qe_invalid;
10331 }
10332
10333
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10334 {
10335 return qe_invalid;
10336 }
10337
10338
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10339 {
10340 return qe_invalid;
10341 }
10342
10343
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10344 {
10345 return qe_invalid;
10346 }
10347
10348
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10349 {
10350 return qe_invalid;
10351 }
10352
10353
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10354 {
10355 return qe_invalid;
10356 }
10357
10358
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10359 {
10360 return qe_invalid;
10361 }
10362
10363
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10364 {
10365 return qe_invalid;
10366 }
10367
10368
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10369 {
10370 return qe_invalid;
10371 }
10372
10373
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10374 {
10375 return qe_invalid;
10376 }
10377
10378
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10379 {
10380
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10381 {
10382 return qe_invalid;
10383 }
10384 3344 }
10385
10386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10387 {
10388 return qe_invalid;
10389 }
10390
10391
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10392 {
10393 return qe_invalid;
10394 }
10395
10396
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10397 {
10398 return qe_invalid;
10399 }
10400
10401
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10402 {
10403 return qe_invalid;
10404 }
10405
10406
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10407 {
10408 return qe_invalid;
10409 }
10410
10411
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10412 {
10413 return qe_invalid;
10414 }
10415
10416
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10417 {
10418 return qe_invalid;
10419 }
10420
10421
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10422 {
10423 return qe_invalid;
10424 }
10425
10426
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10427 {
10428 return qe_invalid;
10429 }
10430
10431
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10432 {
10433 return qe_invalid;
10434 }
10435
10436
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10437 {
10438 return qe_invalid;
10439 }
10440 836 }
10441
10442
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10443 {
10444 9 section_size=writesize;
10445 9 }
10446 18 }
10447
10448
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10449 {
10450 displayinfo("Error: writestrings()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10451 }
10452
10453 9 new_return(0);
10454 9 }
10455
10456 int32_t writestrings_text(PACKFILE *f)
10457 {
10458 std::map<int32_t, int32_t> msglistcache;
10459
10460 for(int32_t index = 1; index<msg_count; index++)
10461 {
10462 for(int32_t i=1; i<msg_count; i++)
10463 {
10464 if(MsgStrings[i].listpos==index)
10465 {
10466 msglistcache[index-1]=i;
10467 break;
10468 }
10469 }
10470 }
10471
10472 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10473 {
10474 fake_pack_writing=(writecycle==0);
10475 char ebuf[32];
10476
10477 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10478
10479 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10480 {
10481 return qe_invalid;
10482 }
10483
10484 for(int32_t i=1; i<msg_count; i++)
10485 {
10486 int32_t str = msglistcache[i-1];
10487
10488 if(!str)
10489 continue;
10490
10491 if(MsgStrings[str].nextstring != 0)
10492 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10493 else
10494 sprintf(ebuf,"\n\n___%d___\n", str);
10495
10496 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10497 {
10498 return qe_invalid;
10499 }
10500
10501 std::string text = MsgStrings[str].serialize();
10502 if (!pfwrite(text.c_str(), text.size(), f))
10503 {
10504 return qe_invalid;
10505 }
10506 }
10507 }
10508
10509 new_return(0);
10510 }
10511
10512 1 int32_t writestrings_tsv(PACKFILE *f)
10513 {
10514 1 std::stringstream ss;
10515
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10533
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10534
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10535
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10536
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10537
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10538
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10539
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10540
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10541
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10542 };
10543
10544
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10545 {
10546
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10547
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10548 1 break;
10549
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10550 }
10551
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10552
10553 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10554
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10555
10556
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10557 {
10558 35 auto& msg = MsgStrings[i];
10559
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10560 {
10561
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10562
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10563
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10564 35 break;
10565
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10566
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10567
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10568 35 }
10569
10570
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10571
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10572 {
10573 return qe_invalid;
10574 }
10575
10576 1 new_return(0);
10577 1 }
10578
10579 void parse_strings_tsv(std::string tsv)
10580 {
10581 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10582 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10583 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10584 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10585 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10586 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10587 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10588 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10589 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10590 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10591 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10592 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10593 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10594 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10595 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10596 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10597 { "margin", [&](auto& msg, auto& text){
10598 std::vector<std::string> strs;
10599 util::split(text, strs, ' ');
10600 if (strs.size() != 4)
10601 throw std::runtime_error("margin field must have 4 components");
10602 msg.margins[0] = std::stoi(strs[0]);
10603 msg.margins[1] = std::stoi(strs[1]);
10604 msg.margins[2] = std::stoi(strs[2]);
10605 msg.margins[3] = std::stoi(strs[3]);
10606 } },
10607 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10608 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10609 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10610 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10611 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10612 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10613 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10614 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10615 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10616 };
10617
10618 std::vector<std::string> rows;
10619 util::split(tsv, rows, '\n');
10620 if (rows.size())
10621 {
10622 std::string last = rows.back();
10623 util::trimstr(last);
10624 if (last.empty())
10625 rows.pop_back();
10626 }
10627 if (rows.size() <= 1)
10628 throw std::runtime_error("missing header row");
10629
10630 std::vector<std::string> columns;
10631 util::split(rows[0], columns, '\t');
10632 for (auto name : columns)
10633 {
10634 if (!fields.contains(name))
10635 throw std::runtime_error(fmt::format("invalid field: {}", name));
10636 }
10637
10638 int start_index = 1;
10639 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10640 start_index += 1;
10641
10642 int num_strings = rows.size() - start_index + 1;
10643 if (num_strings > MAXMSGS-1)
10644 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10645
10646 std::vector<MsgStr> msgs;
10647 msgs.reserve(num_strings);
10648 for (int i = start_index; i < rows.size(); i++)
10649 {
10650 std::vector<std::string> strs;
10651 util::split(rows[i], strs, '\t');
10652 if (strs.size() != columns.size())
10653 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10654
10655 int j = 0;
10656 auto& msg = msgs.emplace_back();
10657 for (auto& name : columns)
10658 {
10659 auto& fn = fields[name];
10660 try
10661 {
10662 fn(msg, strs[j++]);
10663 }
10664 catch (std::exception& ex)
10665 {
10666 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10667 }
10668 }
10669 }
10670
10671 init_msgstrings(0, msgs.size());
10672 for (int i = 0; i < msgs.size(); i++)
10673 MsgStrings[i + 1] = msgs[i];
10674 msg_count = msgs.size() + 1;
10675 msglistcache.clear();
10676 }
10677
10678 bool isblanktile(tiledata *buf, int32_t i);
10679 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10680 {
10681 //these are here to bypass compiler warnings about unused arguments
10682 9 version=version;
10683 9 build=build;
10684
10685 int32_t tiles_used;
10686 9 dword section_id=ID_TILES;
10687 9 dword section_version=V_TILES;
10688 9 al_trace("Counting tiles used\n");
10689 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10692 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10693 9 dword section_size = 0;
10694
10695 //section id
10696
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10697 {
10698 new_return(1);
10699 }
10700
10701 //section version info
10702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10703 {
10704 new_return(2);
10705 }
10706
10707
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10708 {
10709 new_return(3);
10710 }
10711
10712
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10713 {
10714 18 fake_pack_writing=(writecycle==0);
10715
10716 //section size
10717
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10718 {
10719 new_return(4);
10720 }
10721
10722 18 writesize=0;
10723
10724 //finally... section data
10725 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10726
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10727
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10728
10729
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10730 {
10731 new_return(5);
10732 }
10733
10734
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10735 {
10736
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10737 {
10738
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10739 new_return(8);
10740 365770 }
10741 else
10742 {
10743 330614 int format = newtilebuf[start_tile+i].format;
10744
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10745 {
10746 new_return(6);
10747 }
10748
10749
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10750 {
10751 byte temp_tile[128];
10752 327742 byte *di = temp_tile;
10753 327742 byte *src = newtilebuf[start_tile+i].data;
10754
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10755 {
10756 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10757 41950976 ++di;
10758 41950976 }
10759
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10760 {
10761 new_return(7);
10762 }
10763 327742 }
10764
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10765 {
10766 new_return(7);
10767 }
10768 }
10769 696384 }
10770
10771
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10772 {
10773 9 section_size=writesize;
10774 9 }
10775 18 }
10776
10777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10778 {
10779 displayinfo("Error: writetiles()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10780 }
10781
10782 9 new_return(0);
10783 }
10784
10785 /* MIDI Format
10786 section_id LONG
10787 section_version WORD
10788 section_cversion WORD
10789 section_size LONG
10790 midi_flags 32 Byte ? BITFIELD[252]
10791
10792 [
10793 title 36
10794 start 4
10795 loop_start 4
10796 loop_end 4
10797 loop 2
10798 volume 2
10799 midi *
10800 ]
10801
10802 */
10803
10804 9 int32_t writemidis(PACKFILE *f)
10805 {
10806 9 dword section_id=ID_MIDIS;
10807 9 dword section_version=V_MIDIS;
10808 9 dword section_size = 0;
10809
10810 //section id
10811
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10812 {
10813 new_return(1);
10814 }
10815
10816 //section version info
10817
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10818 {
10819 new_return(2);
10820 }
10821
10822
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10823 {
10824 new_return(3);
10825 }
10826
10827
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10828 {
10829 18 fake_pack_writing=(writecycle==0);
10830
10831 //section size
10832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10833 {
10834 new_return(4);
10835 }
10836
10837 18 writesize=0;
10838
10839 //finally... section data
10840
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10841 {
10842 new_return(5);
10843 }
10844
10845
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10846 {
10847
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10848 {
10849
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10850 {
10851 new_return(6);
10852 }
10853
10854
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10855 {
10856 new_return(7);
10857 }
10858
10859
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10860 {
10861 new_return(8);
10862 }
10863
10864
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10865 {
10866 new_return(9);
10867 }
10868
10869
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10870 {
10871 new_return(10);
10872 }
10873
10874
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10875 {
10876 new_return(11);
10877 }
10878
10879
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10880 {
10881 new_return(12);
10882 }
10883
10884 130 byte format = MFORMAT_MIDI;
10885
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10886 {
10887 new_return(13);
10888 }
10889
10890
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10891 130 }
10892 4536 }
10893
10894
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10895 {
10896 9 section_size=writesize;
10897 9 }
10898 18 }
10899
10900
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10901 {
10902 displayinfo("Error: writemidis()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10903 }
10904
10905 9 new_return(0);
10906 }
10907
10908 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10909 {
10910 9 dword section_id=ID_CHEATS;
10911 9 dword section_version=V_CHEATS;
10912 9 dword section_size = 0;
10913
10914 //section id
10915
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10916 {
10917 new_return(1);
10918 }
10919
10920 //section version info
10921
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10922 {
10923 new_return(2);
10924 }
10925
10926
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10927 {
10928 new_return(3);
10929 }
10930
10931
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10932 {
10933 18 fake_pack_writing=(writecycle==0);
10934
10935 //section size
10936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10937 {
10938 new_return(4);
10939 }
10940
10941 18 writesize=0;
10942
10943 //finally... section data
10944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10945 {
10946 new_return(5);
10947 }
10948
10949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10950 {
10951
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10952 {
10953 new_return(6);
10954 }
10955
10956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10957 {
10958 new_return(7);
10959 }
10960 18 }
10961
10962
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10963 {
10964 9 section_size=writesize;
10965 9 }
10966 18 }
10967
10968
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10969 {
10970 displayinfo("Error: writecheats()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
10971 }
10972
10973 9 new_return(0);
10974 }
10975
10976 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10977 {
10978 //these are here to bypass compiler warnings about unused arguments
10979 9 Header=Header;
10980
10981 9 dword section_id=ID_GUYS;
10982 9 dword section_version=V_GUYS;
10983 9 dword section_size=0;
10984
10985 //section id
10986
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10987 {
10988 new_return(1);
10989 }
10990
10991 //section version info
10992
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10993 {
10994 new_return(2);
10995 }
10996
10997
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
10998 {
10999 new_return(3);
11000 }
11001
11002
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11003 {
11004 18 fake_pack_writing=(writecycle==0);
11005
11006 //section size
11007
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11008 {
11009 new_return(4);
11010 }
11011
11012 18 writesize=0;
11013
11014 //finally... section data
11015
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11016 {
11017
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11018 {
11019 new_return(5);
11020 }
11021 9216 }
11022
11023
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11024 {
11025 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11026 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11027
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11028 {
11029 new_return(6);
11030 }
11031
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11032 {
11033 new_return(7);
11034 }
11035
11036
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11037 {
11038 new_return(8);
11039 }
11040
11041
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11042 {
11043 new_return(9);
11044 }
11045
11046
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11047 {
11048 new_return(10);
11049 }
11050
11051
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11052 {
11053 new_return(11);
11054 }
11055
11056
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11057 {
11058 new_return(12);
11059 }
11060
11061
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11062 {
11063 new_return(13);
11064 }
11065
11066
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11067 {
11068 new_return(14);
11069 }
11070
11071
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11072 {
11073 new_return(15);
11074 }
11075
11076
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11077 {
11078 new_return(16);
11079 }
11080
11081
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11082 {
11083 new_return(17);
11084 }
11085
11086
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11087 {
11088 new_return(18);
11089 }
11090
11091
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11092 {
11093 new_return(19);
11094 }
11095
11096
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11097 {
11098 new_return(20);
11099 }
11100
11101
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11102 {
11103 new_return(21);
11104 }
11105
11106
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11107 {
11108 new_return(22);
11109 }
11110
11111
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11112 {
11113 new_return(23);
11114 }
11115
11116
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11117 {
11118 new_return(24);
11119 }
11120
11121
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11122 {
11123 new_return(25);
11124 }
11125
11126
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11127 {
11128 new_return(26);
11129 }
11130
11131
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11132 {
11133 new_return(27);
11134 }
11135
11136
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11137 {
11138 new_return(28);
11139 }
11140
11141
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11142 {
11143 new_return(29);
11144 }
11145
11146
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11147 {
11148 new_return(30);
11149 }
11150
11151
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11152 {
11153 new_return(31);
11154 }
11155
11156
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11157 {
11158 new_return(32);
11159 }
11160
11161
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11162 {
11163 new_return(33);
11164 }
11165
11166
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11167 {
11168 new_return(34);
11169 }
11170
11171
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11172 {
11173 new_return(35);
11174 }
11175
11176
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11177 {
11178 new_return(36);
11179 }
11180
11181
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11182 {
11183 new_return(37);
11184 }
11185
11186
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11187 {
11188 new_return(38);
11189 }
11190
11191
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11192 {
11193 new_return(39);
11194 }
11195
11196
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11197 {
11198 new_return(40);
11199 }
11200
11201
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11202 {
11203 new_return(41);
11204 }
11205
11206
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11207 {
11208 new_return(42);
11209 }
11210
11211
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11212 {
11213 new_return(43);
11214 }
11215
11216
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11217 {
11218 new_return(44);
11219 }
11220
11221
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11222 {
11223 new_return(45);
11224 }
11225
11226
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11227 {
11228
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11229 {
11230 new_return(46);
11231 }
11232 175104 }
11233
11234
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11235 {
11236 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11238 //Force SFX_HIT here.
11239
11240 2048 }
11241
11242
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11243 {
11244 new_return(47);
11245 }
11246
11247
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11248 {
11249 new_return(48);
11250 }
11251
11252
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11253 {
11254 new_return(49);
11255 }
11256
11257
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11258 {
11259 new_return(50);
11260 }
11261
11262 //New 2.6 defences
11263
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11264 {
11265
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11266 {
11267 new_return(51);
11268 }
11269 202752 }
11270
11271 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11272
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11273 {
11274 new_return(52);
11275 }
11276
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11277 {
11278 new_return(53);
11279 }
11280
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11281 {
11282 new_return(54);
11283 }
11284
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11285 {
11286 new_return(55);
11287 }
11288
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11289 {
11290 new_return(56);
11291 }
11292 // These are not fixed types, but ints, so they are safe to use here.
11293
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11294 {
11295 new_return(57);
11296 }
11297
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11298 {
11299 new_return(58);
11300 }
11301
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11302 {
11303 new_return(59);
11304 }
11305
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11306 {
11307 new_return(60);
11308 }
11309
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11310 {
11311 new_return(61);
11312 }
11313
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11314 {
11315 new_return(62);
11316 }
11317
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11318 {
11319 new_return(63);
11320 }
11321
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11322 {
11323 new_return(64);
11324 }
11325
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11326 {
11327 new_return(65);
11328 }
11329
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11330 {
11331 new_return(66);
11332 }
11333
11334
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11335 {
11336
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11337 {
11338 new_return(67);
11339 }
11340 92160 }
11341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11342 {
11343 new_return(68);
11344 }
11345 //misc 16->31
11346
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11347 {
11348 new_return(69);
11349 }
11350
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11351 {
11352 new_return(70);
11353 }
11354
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11355 {
11356 new_return(71);
11357 }
11358
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11359 {
11360 new_return(72);
11361 }
11362
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11363 {
11364 new_return(73);
11365 }
11366
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11367 {
11368 new_return(74);
11369 }
11370
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11371 {
11372 new_return(75);
11373 }
11374
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11375 {
11376 new_return(76);
11377 }
11378
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11379 {
11380 new_return(77);
11381 }
11382
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11383 {
11384 new_return(78);
11385 }
11386
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11387 {
11388 new_return(79);
11389 }
11390
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11391 {
11392 new_return(80);
11393 }
11394
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11395 {
11396 new_return(81);
11397 }
11398
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11399 {
11400 new_return(82);
11401 }
11402
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11403 {
11404 new_return(83);
11405 }
11406
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11407 {
11408 new_return(84);
11409 }
11410
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11411 {
11412 new_return(85);
11413 }
11414
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11415 {
11416
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11417 {
11418 new_return(86);
11419 }
11420 294912 }
11421
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11422 {
11423
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11424 {
11425 new_return(87);
11426 }
11427 294912 }
11428
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11429 {
11430 new_return(88);
11431 }
11432
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11433 {
11434
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11435 {
11436 new_return(89);
11437 }
11438 73728 }
11439
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11440 {
11441
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11442 {
11443 new_return(90);
11444 }
11445 18432 }
11446
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11447 {
11448 new_return(91);
11449 }
11450 //somehow forgot these in the older builds -Z
11451
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11452 {
11453 new_return(92);
11454 }
11455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11456 {
11457 new_return(93);
11458 }
11459
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11460 {
11461 new_return(94);
11462 }
11463
11464 //Enemy Editor InitD[] labels
11465
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11466 {
11467
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11468 {
11469
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11470 {
11471 new_return(95);
11472 }
11473 4792320 }
11474 73728 }
11475
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11476 new_return(99);
11477
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11478 new_return(100);
11479
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11480 new_return(101);
11481
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11482 new_return(102);
11483
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11484 new_return(103);
11485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11486 return ret;
11487 9216 }
11488
11489
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11490 {
11491 9 section_size=writesize;
11492 9 }
11493 18 }
11494
11495
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11496 {
11497 displayinfo("Error: writeguys()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
11498 }
11499
11500 9 new_return(0);
11501 9 }
11502
11503 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11504 {
11505 //these are here to bypass compiler warnings about unused arguments
11506 9 Header=Header;
11507
11508 9 dword section_id=ID_HEROSPRITES;
11509 9 dword section_version=V_HEROSPRITES;
11510 9 dword section_size=0;
11511
11512 //section id
11513
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11514 {
11515 new_return(1);
11516 }
11517
11518 //section version info
11519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11520 {
11521 new_return(2);
11522 }
11523
11524
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
11525 {
11526 new_return(3);
11527 }
11528
11529
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11530 {
11531 18 fake_pack_writing=(writecycle==0);
11532
11533 //section size
11534
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11535 {
11536 new_return(4);
11537 }
11538
11539 18 writesize=0;
11540
11541 //finally... section data
11542
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11543 {
11544
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11545 {
11546 new_return(5);
11547 }
11548
11549
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11550 {
11551 new_return(5);
11552 }
11553
11554
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11555 {
11556 new_return(5);
11557 }
11558 72 }
11559
11560
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11561 {
11562
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11563 {
11564 new_return(6);
11565 }
11566
11567
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11568 {
11569 new_return(6);
11570 }
11571
11572
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11573 {
11574 new_return(6);
11575 }
11576 72 }
11577
11578
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11579 {
11580
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11581 {
11582 new_return(7);
11583 }
11584
11585
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11586 {
11587 new_return(7);
11588 }
11589
11590
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11591 {
11592 new_return(7);
11593 }
11594 72 }
11595
11596
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11597 {
11598
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11599 {
11600 new_return(8);
11601 }
11602
11603
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11604 {
11605 new_return(8);
11606 }
11607
11608
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11609 {
11610 new_return(8);
11611 }
11612 72 }
11613
11614
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11615 {
11616
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11617 {
11618 new_return(8);
11619 }
11620
11621
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11622 {
11623 new_return(8);
11624 }
11625
11626
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11627 {
11628 new_return(8);
11629 }
11630 72 }
11631
11632
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11633 {
11634
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11635 {
11636 new_return(9);
11637 }
11638
11639
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11640 {
11641 new_return(9);
11642 }
11643
11644
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11645 {
11646 new_return(9);
11647 }
11648 72 }
11649
11650
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11651 {
11652
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11653 {
11654 new_return(10);
11655 }
11656
11657
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11658 {
11659 new_return(10);
11660 }
11661
11662
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11663 {
11664 new_return(10);
11665 }
11666 72 }
11667
11668
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11669 {
11670 new_return(11);
11671 }
11672
11673
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11674 {
11675 new_return(11);
11676 }
11677
11678
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11679 {
11680 new_return(11);
11681 }
11682
11683
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11684 {
11685
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11686 {
11687
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11688 {
11689 new_return(12);
11690 }
11691
11692
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11693 {
11694 new_return(12);
11695 }
11696
11697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11698 {
11699 new_return(12);
11700 }
11701 108 }
11702 36 }
11703
11704
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11705 {
11706
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11707 {
11708 new_return(13);
11709 }
11710
11711
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11712 {
11713 new_return(13);
11714 }
11715
11716
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11717 {
11718 new_return(13);
11719 }
11720 72 }
11721
11722
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11723 {
11724
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11725 {
11726 new_return(13);
11727 }
11728
11729
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11730 {
11731 new_return(13);
11732 }
11733
11734
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11735 {
11736 new_return(13);
11737 }
11738 72 }
11739
11740
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11741 {
11742 new_return(14);
11743 }
11744
11745 //{ V_HEROSPRITES >= 7
11746
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11747 {
11748
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11749 new_return(15);
11750
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11751 new_return(15);
11752
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11753 new_return(15);
11754 72 }
11755
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11756 {
11757
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11758 new_return(15);
11759
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11760 new_return(15);
11761
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11762 new_return(15);
11763 72 }
11764
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11765 {
11766
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11767 new_return(15);
11768
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11769 new_return(15);
11770
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11771 new_return(15);
11772 72 }
11773
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11774 {
11775
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11776 new_return(15);
11777
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11778 new_return(15);
11779
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11780 new_return(15);
11781 72 }
11782
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11783 {
11784
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11785 new_return(15);
11786
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11787 new_return(15);
11788
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11789 new_return(15);
11790 72 }
11791
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11792 {
11793
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11794 new_return(15);
11795
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11796 new_return(15);
11797
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11798 new_return(15);
11799 72 }
11800
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11801 {
11802
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11803 new_return(15);
11804
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11805 new_return(15);
11806
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11807 new_return(15);
11808 72 }
11809
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11810 {
11811
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11812 new_return(15);
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11814 new_return(15);
11815
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11816 new_return(15);
11817 72 }
11818
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11819 {
11820
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11821 new_return(15);
11822
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11823 new_return(15);
11824
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11825 new_return(15);
11826
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11827 new_return(15);
11828 72 }
11829
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11830 {
11831
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11832 new_return(15);
11833
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11834 new_return(15);
11835
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11836 new_return(15);
11837 72 }
11838
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11839 {
11840
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11841 new_return(15);
11842
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11843 new_return(15);
11844
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11845 new_return(15);
11846 72 }
11847
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11848 {
11849
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11850 new_return(15);
11851
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11852 new_return(15);
11853
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11854 new_return(15);
11855 72 }
11856
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11857 {
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11859 new_return(15);
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11861 new_return(15);
11862
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11863 new_return(15);
11864 72 }
11865
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11866 {
11867
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11868 new_return(15);
11869
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11870 new_return(15);
11871
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11872 new_return(15);
11873 72 }
11874
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11875 {
11876
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11877 new_return(15);
11878
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11879 new_return(15);
11880
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11881 new_return(15);
11882 72 }
11883
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11884 {
11885
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11886 new_return(15);
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11888 new_return(15);
11889
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11890 new_return(15);
11891 72 }
11892
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11893 {
11894
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11895 new_return(15);
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11897 new_return(15);
11898
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11899 new_return(15);
11900 72 }
11901
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11902 {
11903
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11904 new_return(15);
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11906 new_return(15);
11907
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11908 new_return(15);
11909 72 }
11910
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11911 {
11912
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11913 new_return(15);
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11915 new_return(15);
11916
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11917 new_return(15);
11918 72 }
11919
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11920 {
11921
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11922 new_return(15);
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11924 new_return(15);
11925
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11926 new_return(15);
11927 72 }
11928
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11929 {
11930
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11933 new_return(15);
11934
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11935 new_return(15);
11936 72 }
11937
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11938 {
11939
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11942 new_return(15);
11943
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11944 new_return(15);
11945 72 }
11946
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11947 {
11948
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11951 new_return(15);
11952
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11953 new_return(15);
11954 72 }
11955
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11956 {
11957
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11960 new_return(15);
11961
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11962 new_return(15);
11963 54 }
11964
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11965 {
11966
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11967 new_return(16);
11968
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11969 new_return(16);
11970
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11971 new_return(16);
11972 72 }
11973
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11974 {
11975
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11976 new_return(17);
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11978 new_return(17);
11979
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11980 new_return(17);
11981 72 }
11982
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11983 {
11984
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11985 new_return(17);
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11987 new_return(17);
11988
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11989 new_return(17);
11990 72 }
11991
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11992 {
11993
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
11994 new_return(17);
11995
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
11996 new_return(17);
11997
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
11998 new_return(17);
11999 72 }
12000
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12001 {
12002
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12003 new_return(18);
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12005 new_return(18);
12006
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12007 new_return(18);
12008 72 }
12009
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12010 {
12011
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12012 new_return(19);
12013 72 }
12014
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12015 {
12016
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12017 new_return(20);
12018
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12019 new_return(20);
12020
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12021 new_return(20);
12022 54 }
12023
12024
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12025 {
12026 new_return(21);
12027 }
12028
12029
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12030 {
12031 new_return(21);
12032 }
12033
12034
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12035 {
12036 new_return(21);
12037 }
12038
12039
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12040 {
12041
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12042 new_return(22);
12043
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12044 new_return(22);
12045
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12046 new_return(22);
12047 72 }
12048
12049
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12050 {
12051
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12052 {
12053 new_return(23);
12054 }
12055
12056
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12057 {
12058 new_return(23);
12059 }
12060
12061
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12062 {
12063 new_return(23);
12064 }
12065 72 }
12066
12067
12068
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12069 {
12070
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12071 new_return(15);
12072 2628 }
12073 //}
12074
12075
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12076 {
12077 9 section_size=writesize;
12078 9 }
12079 18 }
12080
12081 //More data will come here
12082
12083
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12084 {
12085 displayinfo("Error: writeherosprites()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12086 }
12087
12088 9 new_return(0);
12089 }
12090
12091 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12092 {
12093 9 dword section_id=ID_SUBSCREEN;
12094 9 dword section_version=V_SUBSCREEN;
12095 9 dword section_size=0;
12096
12097 //section id
12098
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12099 {
12100 new_return(1);
12101 }
12102
12103 //section version info
12104
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12105 {
12106 new_return(2);
12107 }
12108
12109
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12110 {
12111 new_return(3);
12112 }
12113
12114
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12115 {
12116 18 fake_pack_writing=(writecycle==0);
12117
12118 //section size
12119
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12120 {
12121 new_return(4);
12122 }
12123
12124 18 writesize=0;
12125
12126 18 byte sz = subscreens_active.size();
12127
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12128 new_return(5);
12129
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12130 {
12131 86 int32_t ret = subscreens_active[i].write(f);
12132 86 fake_pack_writing=(writecycle==0);
12133
12134
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12135 new_return(ret);
12136 86 }
12137
12138 18 sz = subscreens_passive.size();
12139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(sz,f))
12140 new_return(5);
12141
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12142 {
12143 64 int32_t ret = subscreens_passive[i].write(f);
12144 64 fake_pack_writing=(writecycle==0);
12145
12146
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12147 new_return(ret);
12148 64 }
12149
12150 18 sz = subscreens_overlay.size();
12151
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12152 new_return(5);
12153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12154 {
12155 int32_t ret = subscreens_overlay[i].write(f);
12156 fake_pack_writing=(writecycle==0);
12157
12158 if(ret!=0)
12159 new_return(ret);
12160 }
12161
12162 18 sz = subscreens_map.size();
12163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_putc(sz,f))
12164 new_return(5);
12165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12166 {
12167 int32_t ret = subscreens_map[i].write(f);
12168 fake_pack_writing=(writecycle==0);
12169
12170 if(ret!=0)
12171 new_return(ret);
12172 }
12173
12174
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12175 {
12176 9 section_size=writesize;
12177 9 }
12178 18 }
12179
12180
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12181 {
12182 displayinfo("Error: writesubscreens()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12183 }
12184
12185 9 new_return(0);
12186 9 }
12187
12188 extern script_data *ffscripts[NUMSCRIPTFFC];
12189 extern script_data *itemscripts[NUMSCRIPTITEM];
12190 extern script_data *guyscripts[NUMSCRIPTGUYS];
12191 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12192 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12193 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12194 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12195 extern script_data *playerscripts[NUMSCRIPTHERO];
12196 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12197 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12198 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12199 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12200 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12201
12202 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12203 {
12204
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12205 3 return writeffscript_old(f, Header);
12206
12207 6 dword section_id = ID_FFSCRIPT;
12208 6 dword section_version = V_FFSCRIPT;
12209 6 dword section_size = 0;
12210 6 dword zasmmeta_version = METADATA_V;
12211 6 byte numscripts = 0;
12212 6 numscripts = numscripts; //to avoid unused variables warnings
12213
12214 //section id
12215
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12216 {
12217 new_return(1);
12218 }
12219
12220 //section version info
12221
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12222 {
12223 new_return(2);
12224 }
12225
12226
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12227 {
12228 new_return(3);
12229 }
12230
12231
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12232 {
12233 new_return(4);
12234 }
12235
12236
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12237 {
12238 12 fake_pack_writing=(writecycle==0);
12239
12240 //section size
12241
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12242 {
12243 new_return(5);
12244 }
12245
12246 12 writesize=0;
12247
12248 12 write_quest_zasm(f);
12249
12250
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12251 {
12252 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12253
12254
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12255 {
12256 new_return(ret);
12257 }
12258 6144 }
12259
12260
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12261 {
12262 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12263
12264
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12265 {
12266 new_return(ret);
12267 }
12268 3072 }
12269
12270
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12271 {
12272 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12273
12274
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12275 {
12276 new_return(ret);
12277 }
12278 3072 }
12279
12280
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12281
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12282 {
12283 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12284
12285
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12286 {
12287 new_return(ret);
12288 }
12289 3072 }
12290
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12291
12292
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12293 {
12294 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12295
12296
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12297 {
12298 new_return(ret);
12299 }
12300 3072 }
12301
12302
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12303 {
12304 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12305
12306
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12307 {
12308 new_return(ret);
12309 }
12310 96 }
12311
12312
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12313 {
12314 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12315
12316
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12317 {
12318 new_return(ret);
12319 }
12320 60 }
12321
12322
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12323 {
12324 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12325
12326
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12327 {
12328 new_return(ret);
12329 }
12330 3072 }
12331
12332
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12333 {
12334 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12335
12336
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12337 {
12338 new_return(ret);
12339 }
12340 3072 }
12341
12342
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12343 {
12344 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12345
12346
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12347 {
12348 new_return(ret);
12349 }
12350 3072 }
12351
12352
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12353 {
12354 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12355
12356
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12357 {
12358 new_return(ret);
12359 }
12360 3072 }
12361
12362
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12363 {
12364 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12365
12366
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12367 {
12368 new_return(ret);
12369 }
12370 6144 }
12371
12372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12373 {
12374 new_return(2000);
12375 }
12376
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12377 {
12378 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12379
12380
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12381 {
12382 new_return(ret);
12383 }
12384 6144 }
12385
12386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12387 {
12388 new_return(2001);
12389 }
12390
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12391 {
12392 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12393
12394
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12395 {
12396 new_return(ret);
12397 }
12398 3072 }
12399
12400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12401 {
12402 new_return(2001);
12403 }
12404
12405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12406 {
12407 new_return(2002);
12408 }
12409
12410 12 word numffcbindings=0;
12411
12412
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12413 {
12414
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12415 {
12416 158 numffcbindings++;
12417 158 }
12418 6132 }
12419
12420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12421 {
12422 new_return(2003);
12423 }
12424
12425
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12426 {
12427
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12428 {
12429
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12430 {
12431 new_return(2004);
12432 }
12433
12434
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12435 {
12436 new_return(2005);
12437 }
12438
12439
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12440 {
12441 new_return(2006);
12442 }
12443 158 }
12444 6132 }
12445
12446 12 word numglobalbindings=0;
12447
12448
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12449 {
12450
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12451 {
12452 22 numglobalbindings++;
12453 22 }
12454 96 }
12455
12456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12457 {
12458 new_return(2007);
12459 }
12460
12461
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12462 {
12463
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12464 {
12465
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12466 {
12467 new_return(2008);
12468 }
12469
12470
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12471 {
12472 new_return(2009);
12473 }
12474
12475
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12476 {
12477 new_return(2010);
12478 }
12479 22 }
12480 96 }
12481
12482 12 word numitembindings=0;
12483
12484
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12485 {
12486
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12487 {
12488 26 numitembindings++;
12489 26 }
12490 3060 }
12491
12492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12493 {
12494 new_return(2011);
12495 }
12496
12497
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12498 {
12499
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12500 {
12501
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12502 {
12503 new_return(2012);
12504 }
12505
12506
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12507 {
12508 new_return(2013);
12509 }
12510
12511
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12512 {
12513 new_return(2014);
12514 }
12515 26 }
12516 3060 }
12517
12518 //new script types
12519 //npc scripts
12520 12 word numnpcbindings=0;
12521
12522
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12523 {
12524
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12525 {
12526 numnpcbindings++;
12527 }
12528 3060 }
12529
12530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12531 {
12532 new_return(2015);
12533 }
12534
12535
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12536 {
12537
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12538 {
12539 if(!p_iputw(it->first,f))
12540 {
12541 new_return(2016);
12542 }
12543
12544 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12545 {
12546 new_return(2017);
12547 }
12548
12549 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12550 {
12551 new_return(2018);
12552 }
12553 }
12554 3060 }
12555
12556 //lweapon
12557
12558 12 word numlwpnbindings=0;
12559
12560
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12561 {
12562
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12563 {
12564 2 numlwpnbindings++;
12565 2 }
12566 3060 }
12567
12568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12569 {
12570 new_return(2019);
12571 }
12572
12573
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12574 {
12575
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12576 {
12577
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12578 {
12579 new_return(2020);
12580 }
12581
12582
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12583 {
12584 new_return(2021);
12585 }
12586
12587
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12588 {
12589 new_return(2022);
12590 }
12591 2 }
12592 3060 }
12593
12594 //////
12595
12596 //eweapon
12597
12598
12599 12 word numewpnbindings=0;
12600
12601
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12602 {
12603
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12604 {
12605 numewpnbindings++;
12606 }
12607 3060 }
12608
12609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12610 {
12611 new_return(2023);
12612 }
12613
12614
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12615 {
12616
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12617 {
12618 if(!p_iputw(it->first,f))
12619 {
12620 new_return(2024);
12621 }
12622
12623 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12624 {
12625 new_return(2025);
12626 }
12627
12628 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12629 {
12630 new_return(2026);
12631 }
12632 }
12633 3060 }
12634
12635 //player scripts
12636 12 word numherobindings=0;
12637
12638
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12639 {
12640
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12641 {
12642 numherobindings++;
12643 }
12644 48 }
12645
12646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12647 {
12648 new_return(2027);
12649 }
12650
12651
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12652 {
12653
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12654 {
12655 if(!p_iputw(it->first,f))
12656 {
12657 new_return(2028);
12658 }
12659
12660 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12661 {
12662 new_return(2029);
12663 }
12664
12665 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12666 {
12667 new_return(2030);
12668 }
12669 }
12670 48 }
12671
12672 //dmap scripts
12673 12 word numdmapbindings=0;
12674
12675
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12676 {
12677
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12678 {
12679 10 numdmapbindings++;
12680 10 }
12681 3060 }
12682
12683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12684 {
12685 new_return(2031);
12686 }
12687
12688
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12689 {
12690
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12691 {
12692
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12693 {
12694 new_return(2032);
12695 }
12696
12697
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12698 {
12699 new_return(2033);
12700 }
12701
12702
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12703 {
12704 new_return(2034);
12705 }
12706 10 }
12707 3060 }
12708
12709 //screen scripts
12710 12 word numscreenbindings=0;
12711
12712
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12713 {
12714
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12715 {
12716 4 numscreenbindings++;
12717 4 }
12718 3060 }
12719
12720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12721 {
12722 new_return(2035);
12723 }
12724
12725
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12726 {
12727
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12728 {
12729
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12730 {
12731 new_return(2036);
12732 }
12733
12734
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12735 {
12736 new_return(2037);
12737 }
12738
12739
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12740 {
12741 new_return(2038);
12742 }
12743 4 }
12744 3060 }
12745 //item sprite scripts
12746 12 word numitemspritebindings=0;
12747
12748
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12749 {
12750
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12751 {
12752 numitemspritebindings++;
12753 }
12754 3060 }
12755
12756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12757 {
12758 new_return(2039);
12759 }
12760
12761
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12762 {
12763
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12764 {
12765 if(!p_iputw(it->first,f))
12766 {
12767 new_return(2040);
12768 }
12769
12770 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12771 {
12772 new_return(2041);
12773 }
12774
12775 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12776 {
12777 new_return(2042);
12778 }
12779 }
12780 3060 }
12781
12782 //combo scripts
12783 12 word numcombobindings=0;
12784
12785
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12786 {
12787
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12788 {
12789 numcombobindings++;
12790 }
12791 6132 }
12792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12793 {
12794 new_return(2043);
12795 }
12796
12797
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12798 {
12799
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12800 {
12801 if(!p_iputw(it->first,f))
12802 {
12803 new_return(2044);
12804 }
12805
12806 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12807 {
12808 new_return(2045);
12809 }
12810
12811 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12812 {
12813 new_return(2046);
12814 }
12815 }
12816 6132 }
12817 //subscreen scripts
12818 12 word numgenericbindings=0;
12819
12820
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12821 {
12822
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12823 {
12824 44 numgenericbindings++;
12825 44 }
12826 6132 }
12827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12828 {
12829 new_return(2043);
12830 }
12831
12832
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12833 {
12834
2/2
✓ Branch 0 taken 6088 times.
✓ Branch 1 taken 44 times.
6132 if(it->second.scriptname != "")
12835 {
12836
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputw(it->first,f))
12837 {
12838 new_return(2044);
12839 }
12840
12841
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12842 {
12843 new_return(2045);
12844 }
12845
12846
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12847 {
12848 new_return(2046);
12849 }
12850 44 }
12851 6132 }
12852
12853 //generic scripts
12854 12 word numsubscreenbindings=0;
12855
12856
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12857 {
12858
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12859 {
12860 numsubscreenbindings++;
12861 }
12862 3060 }
12863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12864 {
12865 new_return(2047);
12866 }
12867
12868
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12869 {
12870
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12871 {
12872 if(!p_iputw(it->first,f))
12873 {
12874 new_return(2048);
12875 }
12876
12877 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12878 {
12879 new_return(2049);
12880 }
12881
12882 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12883 {
12884 new_return(2050);
12885 }
12886 }
12887 3060 }
12888
12889
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12890 {
12891 6 section_size=writesize;
12892 6 }
12893 12 }
12894
12895
12896
12897
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12898 {
12899 displayinfo("Error: writeffscript()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
12900 }
12901
12902 6 new_return(0);
12903 //return 0; //this is just here to stomp the compiler from whining.
12904 //the irony is that it causes an "unreachable code" warning.
12905 9 }
12906
12907 12 int32_t write_quest_zasm(PACKFILE *f)
12908 {
12909 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12910
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12911 {
12912 if(!p_iputl(0,f))
12913 new_return(1);
12914
12915 return 0;
12916 }
12917
12918 12 auto& zasm = zasm_scripts[0]->zasm;
12919 12 size_t num_commands = zasm.size();
12920
12921
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12922 new_return(1);
12923
12924
2/2
✓ Branch 0 taken 374290 times.
✓ Branch 1 taken 12 times.
374302 for(int32_t j=0; j<num_commands; j++)
12925 {
12926 374290 auto& zas = zasm[j];
12927
12928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 374290 times.
374290 if(zas.command==0xFFFF)
12929 continue;
12930 else
12931 {
12932
1/2
✓ Branch 0 taken 374290 times.
✗ Branch 1 not taken.
374290 if(!p_iputw(zas.command,f))
12933 new_return(2);
12934
12935
1/2
✓ Branch 0 taken 374290 times.
✗ Branch 1 not taken.
374290 if(!p_iputl(zas.arg1,f))
12936 new_return(3);
12937
12938
1/2
✓ Branch 0 taken 374290 times.
✗ Branch 1 not taken.
374290 if(!p_iputl(zas.arg2,f))
12939 new_return(4);
12940
12941
1/2
✓ Branch 0 taken 374290 times.
✗ Branch 1 not taken.
374290 if(!p_iputl(zas.arg3,f))
12942 new_return(5);
12943
12944 374290 uint32_t sz = 0;
12945
2/2
✓ Branch 0 taken 373232 times.
✓ Branch 1 taken 1058 times.
374290 if(zas.strptr)
12946 1058 sz = zas.strptr->size();
12947
1/2
✓ Branch 0 taken 374290 times.
✗ Branch 1 not taken.
374290 if(!p_iputl(sz,f))
12948 new_return(6);
12949
2/2
✓ Branch 0 taken 373248 times.
✓ Branch 1 taken 1042 times.
374290 if(sz)
12950 {
12951 1042 auto& str = *zas.strptr;
12952
2/2
✓ Branch 0 taken 22474 times.
✓ Branch 1 taken 1042 times.
23516 for(size_t q = 0; q < sz; ++q)
12953 {
12954
1/2
✓ Branch 0 taken 22474 times.
✗ Branch 1 not taken.
22474 if(!p_putc(str[q],f))
12955 new_return(7);
12956 22474 }
12957 1042 }
12958 374290 sz = 0;
12959
2/2
✓ Branch 0 taken 374072 times.
✓ Branch 1 taken 218 times.
374290 if(zas.vecptr)
12960 218 sz = zas.vecptr->size();
12961
1/2
✓ Branch 0 taken 374290 times.
✗ Branch 1 not taken.
374290 if(!p_iputl(sz,f))
12962 new_return(8);
12963
2/2
✓ Branch 0 taken 374072 times.
✓ Branch 1 taken 218 times.
374290 if(sz) //vector found
12964 {
12965 218 auto& vec = *zas.vecptr;
12966
2/2
✓ Branch 0 taken 1320 times.
✓ Branch 1 taken 218 times.
1538 for(size_t q = 0; q < sz; ++q)
12967 {
12968
1/2
✓ Branch 0 taken 1320 times.
✗ Branch 1 not taken.
1320 if(!p_iputl(vec[q],f))
12969 new_return(9);
12970 1320 }
12971 218 }
12972 }
12973 374290 }
12974 12 return 0;
12975 12 }
12976
12977 23370 int32_t write_one_ffscript_meta(PACKFILE *f, zasm_meta const& tmeta)
12978 {
12979
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.zasm_v,f))
12980 new_return(1);
12981
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.meta_v,f))
12982 new_return(2);
12983
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.ffscript_v,f))
12984 new_return(3);
12985
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putc((int)tmeta.script_type,f))
12986 new_return(4);
12987
12988
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(int32_t q = 0; q < 8; ++q)
12989 {
12990
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putcstr(tmeta.run_idens[q],f))
12991 new_return(5);
12992 186960 }
12993
12994
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(int32_t q = 0; q < 8; ++q)
12995
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putc(tmeta.run_types[q],f))
12996 new_return(6);
12997
12998
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putc(tmeta.flags,f))
12999 new_return(7);
13000
13001
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v1,f))
13002 new_return(8);
13003
13004
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v2,f))
13005 new_return(9);
13006
13007
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v3,f))
13008 new_return(10);
13009
13010
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_iputw(tmeta.compiler_v4,f))
13011 new_return(11);
13012
13013
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putcstr(tmeta.script_name,f))
13014 new_return(12);
13015
1/2
✓ Branch 0 taken 23370 times.
✗ Branch 1 not taken.
23370 if(!p_putcstr(tmeta.author,f))
13016 new_return(13);
13017
13018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23370 times.
23370 if (!p_iputw(NUM_ZMETA_ATTRIBUTES, f))
13019 new_return(27);
13020
2/2
✓ Branch 0 taken 560880 times.
✓ Branch 1 taken 23370 times.
584250 for(auto q = 0; q < NUM_ZMETA_ATTRIBUTES; ++q)
13021 {
13022
1/2
✓ Branch 0 taken 560880 times.
✗ Branch 1 not taken.
560880 if(!p_putcstr(tmeta.attributes[q],f))
13023 new_return(28);
13024
1/2
✓ Branch 0 taken 560880 times.
✗ Branch 1 not taken.
560880 if(!p_putwstr(tmeta.attributes_help[q],f))
13025 new_return(29);
13026 560880 }
13027
2/2
✓ Branch 0 taken 373920 times.
✓ Branch 1 taken 23370 times.
397290 for(auto q = 0; q < 16; ++q)
13028 {
13029
1/2
✓ Branch 0 taken 373920 times.
✗ Branch 1 not taken.
373920 if(!p_putcstr(tmeta.usrflags[q],f))
13030 new_return(20);
13031
1/2
✓ Branch 0 taken 373920 times.
✗ Branch 1 not taken.
373920 if(!p_putwstr(tmeta.usrflags_help[q],f))
13032 new_return(21);
13033 373920 }
13034
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(auto q = 0; q < 8; ++q)
13035 {
13036
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putcstr(tmeta.initd[q],f))
13037 new_return(22);
13038
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putwstr(tmeta.initd_help[q],f))
13039 new_return(23);
13040 186960 }
13041
2/2
✓ Branch 0 taken 186960 times.
✓ Branch 1 taken 23370 times.
210330 for(auto q = 0; q < 8; ++q)
13042 {
13043
1/2
✓ Branch 0 taken 186960 times.
✗ Branch 1 not taken.
186960 if(!p_putc(tmeta.initd_type[q],f))
13044 new_return(24);
13045 186960 }
13046
13047 23370 return 0;
13048 }
13049
13050 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13051 {
13052
2/2
✓ Branch 0 taken 45984 times.
✓ Branch 1 taken 252 times.
46236 if (!script->valid())
13053 {
13054
1/2
✓ Branch 0 taken 45984 times.
✗ Branch 1 not taken.
45984 if (!p_putc(0, f))
13055 new_return(-1);
13056 45984 return 0;
13057 }
13058
13059
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if (!p_putc(1, f))
13060 new_return(-1);
13061
13062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (auto ret = write_one_ffscript_meta(f, script->meta))
13063 return ret;
13064
13065
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(!p_iputl(script->pc, f))
13066 new_return(25);
13067
13068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!p_iputl(script->end_pc, f))
13069 new_return(26);
13070
13071 252 return 0;
13072 46236 }
13073
13074 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13075 {
13076 3 dword section_id = ID_FFSCRIPT;
13077 3 dword section_version = 26;
13078 3 dword section_cversion = 1;
13079 3 dword section_size = 0;
13080 3 dword zasmmeta_version = METADATA_V;
13081 3 byte numscripts = 0;
13082 3 numscripts = numscripts; //to avoid unused variables warnings
13083
13084 //section id
13085
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13086 {
13087 new_return(1);
13088 }
13089
13090 //section version info
13091
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13092 {
13093 new_return(2);
13094 }
13095
13096
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13097 {
13098 new_return(3);
13099 }
13100
13101
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13102 {
13103 new_return(4);
13104 }
13105
13106
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13107 {
13108 6 fake_pack_writing=(writecycle==0);
13109
13110 //section size
13111
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13112 {
13113 new_return(5);
13114 }
13115
13116 6 writesize=0;
13117
13118
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13119 {
13120 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13121 3072 fake_pack_writing=(writecycle==0);
13122
13123
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13124 {
13125 new_return(ret);
13126 }
13127 3072 }
13128
13129
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13130 {
13131 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13132 1536 fake_pack_writing=(writecycle==0);
13133
13134
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13135 {
13136 new_return(ret);
13137 }
13138 1536 }
13139
13140
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13141 {
13142 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13143 1536 fake_pack_writing=(writecycle==0);
13144
13145
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13146 {
13147 new_return(ret);
13148 }
13149 1536 }
13150
13151
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13152
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13153 {
13154 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13155 1536 fake_pack_writing=(writecycle==0);
13156
13157
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13158 {
13159 new_return(ret);
13160 }
13161 1536 }
13162
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13163
13164
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13165 {
13166 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13167 1536 fake_pack_writing=(writecycle==0);
13168
13169
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13170 {
13171 new_return(ret);
13172 }
13173 1536 }
13174
13175
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13176 {
13177 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13178 48 fake_pack_writing=(writecycle==0);
13179
13180
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13181 {
13182 new_return(ret);
13183 }
13184 48 }
13185
13186
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13187 {
13188 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13189 30 fake_pack_writing=(writecycle==0);
13190
13191
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13192 {
13193 new_return(ret);
13194 }
13195 30 }
13196
13197
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13198 {
13199 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13200 1536 fake_pack_writing=(writecycle==0);
13201
13202
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13203 {
13204 new_return(ret);
13205 }
13206 1536 }
13207
13208
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13209 {
13210 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13211 1536 fake_pack_writing=(writecycle==0);
13212
13213
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13214 {
13215 new_return(ret);
13216 }
13217 1536 }
13218
13219
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13220 {
13221 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13222 1536 fake_pack_writing=(writecycle==0);
13223
13224
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13225 {
13226 new_return(ret);
13227 }
13228 1536 }
13229
13230
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13231 {
13232 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13233 1536 fake_pack_writing=(writecycle==0);
13234
13235
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13236 {
13237 new_return(ret);
13238 }
13239 1536 }
13240
13241
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13242 {
13243 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13244 3072 fake_pack_writing=(writecycle==0);
13245
13246
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13247 {
13248 new_return(ret);
13249 }
13250 3072 }
13251
13252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13253 {
13254 new_return(2000);
13255 }
13256
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13257 {
13258 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13259 3072 fake_pack_writing=(writecycle==0);
13260
13261
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13262 {
13263 new_return(ret);
13264 }
13265 3072 }
13266
13267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13268 {
13269 new_return(2001);
13270 }
13271
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13272 {
13273 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13274 1536 fake_pack_writing=(writecycle==0);
13275
13276
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13277 {
13278 new_return(ret);
13279 }
13280 1536 }
13281
13282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13283 {
13284 new_return(2001);
13285 }
13286
13287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13288 {
13289 new_return(2002);
13290 }
13291
13292 6 word numffcbindings=0;
13293
13294
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13295 {
13296
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13297 {
13298 206 numffcbindings++;
13299 206 }
13300 3066 }
13301
13302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13303 {
13304 new_return(2003);
13305 }
13306
13307
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13308 {
13309
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13310 {
13311
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13312 {
13313 new_return(2004);
13314 }
13315
13316
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13317 {
13318 new_return(2005);
13319 }
13320
13321
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13322 {
13323 new_return(2006);
13324 }
13325 206 }
13326 3066 }
13327
13328 6 word numglobalbindings=0;
13329
13330
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13331 {
13332
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13333 {
13334 18 numglobalbindings++;
13335 18 }
13336 48 }
13337
13338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13339 {
13340 new_return(2007);
13341 }
13342
13343
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13344 {
13345
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13346 {
13347
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13348 {
13349 new_return(2008);
13350 }
13351
13352
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13353 {
13354 new_return(2009);
13355 }
13356
13357
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13358 {
13359 new_return(2010);
13360 }
13361 18 }
13362 48 }
13363
13364 6 word numitembindings=0;
13365
13366
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13367 {
13368
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13369 {
13370 18 numitembindings++;
13371 18 }
13372 1530 }
13373
13374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13375 {
13376 new_return(2011);
13377 }
13378
13379
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13380 {
13381
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13382 {
13383
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13384 {
13385 new_return(2012);
13386 }
13387
13388
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13389 {
13390 new_return(2013);
13391 }
13392
13393
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13394 {
13395 new_return(2014);
13396 }
13397 18 }
13398 1530 }
13399
13400 //new script types
13401 //npc scripts
13402 6 word numnpcbindings=0;
13403
13404
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13405 {
13406
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13407 {
13408 numnpcbindings++;
13409 }
13410 1530 }
13411
13412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13413 {
13414 new_return(2015);
13415 }
13416
13417
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13418 {
13419
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13420 {
13421 if(!p_iputw(it->first,f))
13422 {
13423 new_return(2016);
13424 }
13425
13426 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13427 {
13428 new_return(2017);
13429 }
13430
13431 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13432 {
13433 new_return(2018);
13434 }
13435 }
13436 1530 }
13437
13438 //lweapon
13439
13440 6 word numlwpnbindings=0;
13441
13442
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13443 {
13444
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13445 {
13446 numlwpnbindings++;
13447 }
13448 1530 }
13449
13450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13451 {
13452 new_return(2019);
13453 }
13454
13455
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13456 {
13457
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13458 {
13459 if(!p_iputw(it->first,f))
13460 {
13461 new_return(2020);
13462 }
13463
13464 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13465 {
13466 new_return(2021);
13467 }
13468
13469 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13470 {
13471 new_return(2022);
13472 }
13473 }
13474 1530 }
13475
13476 //////
13477
13478 //eweapon
13479
13480
13481 6 word numewpnbindings=0;
13482
13483
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13484 {
13485
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13486 {
13487 numewpnbindings++;
13488 }
13489 1530 }
13490
13491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13492 {
13493 new_return(2023);
13494 }
13495
13496
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13497 {
13498
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13499 {
13500 if(!p_iputw(it->first,f))
13501 {
13502 new_return(2024);
13503 }
13504
13505 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13506 {
13507 new_return(2025);
13508 }
13509
13510 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13511 {
13512 new_return(2026);
13513 }
13514 }
13515 1530 }
13516
13517 //player scripts
13518 6 word numherobindings=0;
13519
13520
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13521 {
13522
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13523 {
13524 2 numherobindings++;
13525 2 }
13526 24 }
13527
13528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13529 {
13530 new_return(2027);
13531 }
13532
13533
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13534 {
13535
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13536 {
13537
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13538 {
13539 new_return(2028);
13540 }
13541
13542
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13543 {
13544 new_return(2029);
13545 }
13546
13547
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13548 {
13549 new_return(2030);
13550 }
13551 2 }
13552 24 }
13553
13554 //dmap scripts
13555 6 word numdmapbindings=0;
13556
13557
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13558 {
13559
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13560 {
13561 numdmapbindings++;
13562 }
13563 1530 }
13564
13565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13566 {
13567 new_return(2031);
13568 }
13569
13570
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13571 {
13572
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13573 {
13574 if(!p_iputw(it->first,f))
13575 {
13576 new_return(2032);
13577 }
13578
13579 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13580 {
13581 new_return(2033);
13582 }
13583
13584 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13585 {
13586 new_return(2034);
13587 }
13588 }
13589 1530 }
13590
13591 //screen scripts
13592 6 word numscreenbindings=0;
13593
13594
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13595 {
13596
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13597 {
13598 14 numscreenbindings++;
13599 14 }
13600 1530 }
13601
13602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13603 {
13604 new_return(2035);
13605 }
13606
13607
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13608 {
13609
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13610 {
13611
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13612 {
13613 new_return(2036);
13614 }
13615
13616
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13617 {
13618 new_return(2037);
13619 }
13620
13621
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13622 {
13623 new_return(2038);
13624 }
13625 14 }
13626 1530 }
13627 //item sprite scripts
13628 6 word numitemspritebindings=0;
13629
13630
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13631 {
13632
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13633 {
13634 numitemspritebindings++;
13635 }
13636 1530 }
13637
13638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13639 {
13640 new_return(2039);
13641 }
13642
13643
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13644 {
13645
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13646 {
13647 if(!p_iputw(it->first,f))
13648 {
13649 new_return(2040);
13650 }
13651
13652 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13653 {
13654 new_return(2041);
13655 }
13656
13657 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13658 {
13659 new_return(2042);
13660 }
13661 }
13662 1530 }
13663
13664 //combo scripts
13665 6 word numcombobindings=0;
13666
13667
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13668 {
13669
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13670 {
13671 numcombobindings++;
13672 }
13673 3066 }
13674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13675 {
13676 new_return(2043);
13677 }
13678
13679
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13680 {
13681
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13682 {
13683 if(!p_iputw(it->first,f))
13684 {
13685 new_return(2044);
13686 }
13687
13688 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13689 {
13690 new_return(2045);
13691 }
13692
13693 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13694 {
13695 new_return(2046);
13696 }
13697 }
13698 3066 }
13699 //subscreen scripts
13700 6 word numgenericbindings=0;
13701
13702
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13703 {
13704
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13705 {
13706 numgenericbindings++;
13707 }
13708 3066 }
13709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13710 {
13711 new_return(2043);
13712 }
13713
13714
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13715 {
13716
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13717 {
13718 if(!p_iputw(it->first,f))
13719 {
13720 new_return(2044);
13721 }
13722
13723 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13724 {
13725 new_return(2045);
13726 }
13727
13728 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13729 {
13730 new_return(2046);
13731 }
13732 }
13733 3066 }
13734
13735 //generic scripts
13736 6 word numsubscreenbindings=0;
13737
13738
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13739 {
13740
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13741 {
13742 numsubscreenbindings++;
13743 }
13744 1530 }
13745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13746 {
13747 new_return(2047);
13748 }
13749
13750
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13751 {
13752
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13753 {
13754 if(!p_iputw(it->first,f))
13755 {
13756 new_return(2048);
13757 }
13758
13759 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13760 {
13761 new_return(2049);
13762 }
13763
13764 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13765 {
13766 new_return(2050);
13767 }
13768 }
13769 1530 }
13770
13771
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13772 {
13773 3 section_size=writesize;
13774 3 }
13775 6 }
13776
13777
13778
13779
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13780 {
13781 displayinfo("Error: writeffscript()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
13782 }
13783
13784 3 new_return(0);
13785 //return 0; //this is just here to stomp the compiler from whining.
13786 //the irony is that it causes an "unreachable code" warning.
13787 3 }
13788
13789 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13790 {
13791
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13792
13793
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13794 {
13795 new_return(6);
13796 }
13797
13798 //Metadata
13799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if (auto ret = write_one_ffscript_meta(f, script->meta))
13800 return ret;
13801
13802
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13803 {
13804 2056888 auto& zas = script->zasm_script->zasm[j];
13805
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13806 {
13807 new_return(20);
13808 }
13809
13810
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13811 {
13812 11830 break;
13813 }
13814 else
13815 {
13816
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13817 {
13818 new_return(21);
13819 }
13820
13821
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13822 {
13823 new_return(22);
13824 }
13825
13826
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13827 {
13828 new_return(23);
13829 }
13830
13831 2045058 uint32_t sz = 0;
13832
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(zas.strptr)
13833 2340 sz = zas.strptr->size();
13834
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13835 {
13836 new_return(23);
13837 }
13838
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13839 {
13840 2340 auto& str = *zas.strptr;
13841
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13842 {
13843
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13844 {
13845 new_return(24);
13846 }
13847 214720 }
13848 2340 }
13849 2045058 sz = 0;
13850
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13851 22 sz = zas.vecptr->size();
13852
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13853 {
13854 new_return(25);
13855 }
13856
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13857 {
13858 22 auto& vec = *zas.vecptr;
13859
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13860 {
13861
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13862 {
13863 new_return(26);
13864 }
13865 352 }
13866 22 }
13867 }
13868 2045058 }
13869
13870 23118 new_return(0);
13871 23118 }
13872
13873 extern SAMPLE customsfxdata[WAV_COUNT];
13874 extern uint8_t customsfxflag[WAV_COUNT>>3];
13875
13876 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13877 {
13878 //these are here to bypass compiler warnings about unused arguments
13879 9 Header=Header;
13880
13881 9 dword section_id=ID_SFX;
13882 9 dword section_version=V_SFX;
13883 9 dword section_size=0;
13884
13885 //section id
13886
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
13887 {
13888 new_return(1);
13889 }
13890
13891 //section version info
13892
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
13893 {
13894 new_return(2);
13895 }
13896
13897
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
13898 {
13899 new_return(3);
13900 }
13901
13902
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13903 {
13904 18 fake_pack_writing=(writecycle==0);
13905
13906 //section size
13907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
13908 {
13909 new_return(4);
13910 }
13911
13912 18 writesize=0;
13913
13914
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13915 {
13916
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
13917 {
13918 new_return(5);
13919 }
13920 576 }
13921
13922
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
13923 {
13924
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
13925 3330 continue;
13926
13927
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
13928 {
13929 new_return(5);
13930 }
13931 1260 }
13932
13933
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
13934 {
13935
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
13936 3330 continue;
13937
13938
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
13939 {
13940 new_return(5);
13941 }
13942
13943
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
13944 {
13945 new_return(6);
13946 }
13947
13948
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
13949 {
13950 new_return(7);
13951 }
13952
13953
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
13954 {
13955 new_return(8);
13956 }
13957
13958
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
13959 {
13960 new_return(9);
13961 }
13962
13963
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
13964 {
13965 new_return(10);
13966 }
13967
13968
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
13969 {
13970 new_return(11);
13971 }
13972
13973
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
13974 {
13975 new_return(12);
13976 }
13977
13978 //de-endianfy the data
13979 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13980
13981
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 28596352 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
13982 {
13983
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13984 {
13985 new_return(13);
13986 }
13987 28596352 }
13988 1260 }
13989
13990
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
13991 {
13992 9 section_size=writesize;
13993 9 }
13994 18 }
13995
13996
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
13997 {
13998 displayinfo("Error: writesfx()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
13999 }
14000
14001 9 new_return(0);
14002 }
14003
14004 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14005 {
14006 9 dword section_id=ID_INITDATA;
14007 9 dword section_version=V_INITDATA;
14008 9 dword section_size = 0;
14009
14010 9 zinit.last_map=Map.getCurrMap();
14011 9 zinit.last_screen=Map.getCurrScr();
14012 9 zinit.normalize();
14013
14014 //section id
14015
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14016 {
14017 new_return(1);
14018 }
14019
14020 //section version info
14021
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14022 {
14023 new_return(2);
14024 }
14025
14026
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14027 {
14028 new_return(3);
14029 }
14030
14031 //TODO
14032
14033
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14034 {
14035 18 fake_pack_writing=(writecycle==0);
14036
14037 //section size
14038
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14039 new_return(4);
14040
14041 18 writesize=0;
14042
14043
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14044
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14045 new_return(5);
14046
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14047 {
14048
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14049 new_return(6);
14050 9216 }
14051
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14052 new_return(10);
14053
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14054 new_return(11);
14055
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14056
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14057 new_return(12);
14058
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14059
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14060 new_return(13);
14061
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14062 new_return(14);
14063
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14064 new_return(15);
14065
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14066 new_return(16);
14067
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14068 new_return(17);
14069
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14070 new_return(18);
14071
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14072 new_return(19);
14073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14074 new_return(20);
14075
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14076 new_return(21);
14077
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14078 new_return(22);
14079
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14080 new_return(23);
14081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14082 new_return(24);
14083
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14084 new_return(25);
14085
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14086 new_return(26);
14087
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14088 new_return(27);
14089
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14090 new_return(28);
14091
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14092 new_return(29);
14093
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14094 new_return(30);
14095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14096 new_return(31);
14097
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14098 new_return(32);
14099
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14100 new_return(33);
14101
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14102 new_return(34);
14103
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14104 new_return(35);
14105
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14106 new_return(36);
14107
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14108 new_return(37);
14109
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14110 new_return(38);
14111
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14112 new_return(39);
14113
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14114 new_return(40);
14115
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14116 new_return(41);
14117
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14118 new_return(42);
14119
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14120 new_return(43);
14121
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14122 new_return(44);
14123
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14124 new_return(45);
14125
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14126 new_return(46);
14127
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14128 new_return(47);
14129
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14130 new_return(48);
14131
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14132 new_return(49);
14133
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14134 new_return(50);
14135
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14136 new_return(51);
14137
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14138 new_return(52);
14139
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14140 new_return(53);
14141
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14142 new_return(54);
14143
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14144 new_return(55);
14145
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14146 new_return(56);
14147
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14148 new_return(57);
14149
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14150 new_return(58);
14151
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14152 new_return(59);
14153
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14154 new_return(60);
14155
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14156 new_return(61);
14157
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14158 new_return(62);
14159
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14160 new_return(63);
14161
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14162 new_return(64);
14163
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14164 new_return(65);
14165
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14166 new_return(66);
14167
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14168 new_return(67);
14169
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14170 new_return(68);
14171
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14172 new_return(69);
14173
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14174 new_return(70);
14175
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14176 new_return(71);
14177
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14178 new_return(72);
14179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14180 new_return(73);
14181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14182 new_return(74);
14183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14184 new_return(75);
14185
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14186
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14187 new_return(76);
14188
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14189 new_return(77);
14190
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14191 new_return(78);
14192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14193 new_return(79);
14194
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14195 new_return(80);
14196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14197 new_return(81);
14198
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14199
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14200 new_return(82);
14201
14202
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14203 {
14204 9 section_size=writesize;
14205 9 }
14206 18 }
14207
14208
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14209 {
14210 displayinfo("Error: writeinitdata()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14211 }
14212
14213 9 new_return(0);
14214 }
14215
14216 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14217 {
14218 //these are here to bypass compiler warnings about unused arguments
14219 9 Header=Header;
14220
14221 9 dword section_id=ID_ITEMDROPSETS;
14222 9 dword section_version=V_ITEMDROPSETS;
14223 // dword section_size=0;
14224 9 dword section_size = 0;
14225 9 word num_item_drop_sets=count_item_drop_sets();
14226
14227 //section id
14228
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14229 {
14230 new_return(1);
14231 }
14232
14233 //section version info
14234
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14235 {
14236 new_return(2);
14237 }
14238
14239
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14240 {
14241 new_return(3);
14242 }
14243
14244
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14245 {
14246 18 fake_pack_writing=(writecycle==0);
14247
14248 //section size
14249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14250 {
14251 new_return(4);
14252 }
14253
14254 18 writesize=0;
14255
14256 //finally... section data
14257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14258 {
14259 new_return(5);
14260 }
14261
14262
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14263 {
14264
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14265 {
14266 new_return(6);
14267 }
14268
14269
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14270 {
14271
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14272 {
14273 new_return(7);
14274 }
14275 2360 }
14276
14277
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 2596 times.
2832 for(int32_t j=0; j<11; ++j)
14278 {
14279
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14280 {
14281 new_return(8);
14282 }
14283 2596 }
14284 236 }
14285
14286
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14287 {
14288 9 section_size=writesize;
14289 9 }
14290 18 }
14291
14292
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14293 {
14294 displayinfo("Error: writeitemdropsets()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14295 }
14296
14297 9 new_return(0);
14298 }
14299
14300 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14301 {
14302 9 dword section_id=ID_FAVORITES;
14303 9 dword section_version=V_FAVORITES;
14304 9 dword section_size = 0;
14305
14306 //section id
14307
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14308 {
14309 new_return(1);
14310 }
14311
14312 //section version info
14313
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14314 {
14315 new_return(2);
14316 }
14317
14318
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
14319 {
14320 new_return(3);
14321 }
14322
14323
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14324 {
14325 18 fake_pack_writing=(writecycle==0);
14326
14327 //section size
14328
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14329 new_return(4);
14330
14331 18 writesize=0;
14332
14333
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14334 new_return(16);
14335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14336 new_return(17);
14337
14338 18 word favcmb_cnt = 0;
14339
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14340
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14341 {
14342 14 favcmb_cnt = q+1;
14343 14 break;
14344 }
14345
14346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14347 new_return(5);
14348
14349
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14350 {
14351
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14352 new_return(6);
14353
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14354 new_return(7);
14355 460 }
14356
14357
14358 18 word max_combo_cols = MAX_COMBO_COLS;
14359
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14360 new_return(9);
14361
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14362 {
14363
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14364 new_return(10);
14365
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14366 new_return(11);
14367
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14368 new_return(12);
14369 72 }
14370 18 word max_mappages = MAX_MAPPAGE_BTNS;
14371
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14372 new_return(13);
14373
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14374 {
14375
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14376 new_return(14);
14377
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14378 new_return(15);
14379 162 }
14380
14381
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14382 {
14383 9 section_size=writesize;
14384 9 }
14385 18 }
14386
14387
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14388 {
14389 displayinfo("Error: writefavorites()",fmt::format("writesize != section_size\n{} != {}", writesize, section_size));
14390 }
14391
14392 9 new_return(0);
14393 }
14394
14395 9 int32_t write_adv_music(PACKFILE *f, zquestheader*)
14396 {
14397 9 dword section_id = ID_ADVMUSIC;
14398 9 dword section_version = V_ADVMUSIC;
14399 9 dword section_size = 0;
14400
14401 //section id
14402
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14403 new_return(1);
14404 //section version info
14405
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14406 new_return(2);
14407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14408 new_return(3);
14409
14410 9 size_t count = quest_music.size();
14411
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (count > MAX_QUEST_MUSIC) // shouldn't happen
14412 {
14413 count = MAX_QUEST_MUSIC;
14414 box_out(" ...too many? truncating...");
14415 }
14416
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14417 {
14418 18 fake_pack_writing = (writecycle==0);
14419
14420 //section size
14421
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14422 new_return(4);
14423
14424 18 writesize = 0;
14425
14426
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(count,f))
14427 new_return(5);
14428
14429
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 18 times.
196 for (size_t q = 0; q < count; ++q)
14430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if (auto ret = quest_music[q].write(f))
14431 return ret;
14432
14433
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle == 0)
14434 9 section_size = writesize;
14435 18 }
14436 9 new_return(0);
14437 9 }
14438
14439 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14440 {
14441
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14442 9 reset_combo_animations();
14443 9 reset_combo_animations2();
14444 9 strcpy(header.id_str,QH_NEWIDSTR);
14445 9 header.zelda_version = ZELDA_VERSION;
14446 9 header.internal = INTERNAL_VERSION;
14447 9 header.data_flags[ZQ_TILES] = true;
14448 9 header.data_flags[ZQ_CHEATS2] = 1;
14449 9 header.build=VERSION_BUILD;
14450
14451
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14452 {
14453 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14454 2268 }
14455
14456 char zinfofilename[2048];
14457 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14458
14459 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14460 9 box_out("Saving Quest...");
14461 9 box_eol();
14462 9 box_eol();
14463
14464
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14465
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14466
14467
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14468 return 1;
14469
14470
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14471
14472
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14473 return 2;
14474
14475
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14476
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14477
14478
14479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14480 {
14481 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14482
14483 box_out("Writing ZInfo...");
14484 if(inf)
14485 {
14486 if(writezinfo(inf,ZI)!=0)
14487 return 2;
14488
14489 pack_fclose(inf);
14490 box_out("okay.");
14491 }
14492 else box_out(" ...file failure");
14493 box_eol();
14494 }
14495 else
14496 {
14497
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14498
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14499 return 2;
14500
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14501
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14502 }
14503
14504
14505
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14506
14507
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14508 return 3;
14509
14510
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14511
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14512
14513
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14514
14515
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14516 return 4;
14517
14518
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14520
14521
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14522
14523
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14524 return 5;
14525
14526
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14527
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14528
14529
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14530
14531
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14532 return 6;
14533
14534
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14535
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14536
14537
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14538
14539
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14540 return 7;
14541
14542
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14543
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14544
14545
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14546
14547
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14548 return 8;
14549
14550
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14551
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14552
14553
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14554
14555
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14556 return 9;
14557
14558
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14559
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14560
14561
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14562
14563
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14564 return 10;
14565
14566
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14567
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14568
14569
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14570
14571
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14572 return 11;
14573
14574
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14575
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14576
14577
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14578
14579
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14580 return 12;
14581
14582
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14583
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14584
14585
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14586
14587
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14588 return 13;
14589
14590
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14591
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14592
14593
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14594
14595
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14596 return 14;
14597
14598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14599
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14600
14601
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14602
14603
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14604 return 15;
14605
14606
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14607
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14608
14609
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14610
14611
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14612 return 16;
14613
14614
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14615
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14616
14617
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14618
14619
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14620 return 17;
14621
14622
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14623
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14624
14625
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14626
14627
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14628 return 18;
14629
14630
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14631
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14632
14633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14634
14635
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14636 return 19;
14637
14638
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14639
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14640
14641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14642
14643
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14644 return 20;
14645
14646
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14647
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14648
14649
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14650
14651
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14652 return 21;
14653
14654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14655
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14656
14657
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14658
14659
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14660 return 22;
14661
14662
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14663
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14664
14665
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14666
14667
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14668 return 23;
14669
14670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14672
14673
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14674
14675
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14676 return 24;
14677
14678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14679
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14680
14681
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14682
14683
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14684 return 25;
14685
14686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14687
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14688
14689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14690
14691
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14692 return 26;
14693
14694
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14695
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14696
14697
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Advanced Music...");
14698
14699
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(write_adv_music(f, &header)!=0)
14700 return 27;
14701
14702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14703
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14704
14705
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14706
14707
14708
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14709 {
14710 char const* kfname = filename;
14711 char keyfilename[2048]={0};
14712 zprint2("Writing key files for '%s'\n", kfname);
14713
14714 char temp_pw[QSTPWD_LEN] = {0};
14715 uint ind = 0;
14716 for(char const* ext : {"key","zpwd","zcheat"})
14717 {
14718 replace_extension(keyfilename, kfname, ext, 2047);
14719 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14720 char msg[80] = {0};
14721 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14722 msg[78]=13;
14723 msg[79]=10;
14724 pfwrite(msg, 80, fp);
14725 p_iputw(header.zelda_version,fp);
14726 p_putc(header.build,fp);
14727 char const* pwd = header.password;
14728 if(ind == 2) //.zcheat, hashed pwd
14729 {
14730 char hashmap = 'Z';
14731 hashmap += 'Q';
14732 hashmap += 'U';
14733 hashmap += 'E';
14734 hashmap += 'S';
14735 hashmap += 'T';
14736 for ( int q = 0; q < QSTPWD_LEN; ++q )
14737 {
14738 temp_pw[q] = header.password[q];
14739 temp_pw[q] += hashmap;
14740 }
14741 pwd = temp_pw;
14742 }
14743 pfwrite(pwd, strlen(pwd), fp);
14744 pack_fclose(fp);
14745 ++ind;
14746 }
14747 }
14748
14749 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14750 9 std::error_code ec;
14751
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14753 {
14754 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14755 return ec.value();
14756 }
14757
14758
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14759
14760 #ifdef __EMSCRIPTEN__
14761 em_sync_fs();
14762 #endif
14763
14764 9 return 0;
14765 9 }
14766
14767 // #ifdef _WIN32
14768 // static std::time_t to_time_t(FILETIME const& ft) {
14769 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14770 // t -= 116444736000000000ull;
14771 // t /= 10000000u;
14772 // return static_cast<std::time_t>(t);
14773 // }
14774 // #else
14775 // #endif
14776 template<typename TP>
14777 5 static std::time_t to_time_t(TP tp) {
14778 using namespace std::chrono;
14779 5 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14780 5 return system_clock::to_time_t(sctp);
14781 }
14782
14783 5 std::string get_time_last_modified_string(std::string path)
14784 {
14785
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 auto write_time = fs::last_write_time(path);
14786 // TODO: C++20 but not supported yet.
14787 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14788 5 std::time_t tt = to_time_t(write_time);
14789 5 std::tm *gmt = std::gmtime(&tt);
14790 5 std::stringstream buffer;
14791
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 buffer << std::put_time(gmt, "%Y-%m-%d");
14792
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string formattedFileTime = buffer.str();
14793 5 return formattedFileTime;
14794
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 }
14795
14796 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14797 {
14798 // Always backup quest if it was last saved in a different version of the editor,
14799 // or if this a new file and is overwritting another qst file.
14800
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14801 {
14802 5 std::string backup_name;
14803
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string last_mod = get_time_last_modified_string(filename);
14804
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (strlen(header.zelda_version_string) > 0)
14805 {
14806
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14807 5 }
14808 else
14809 {
14810 backup_name = fmt::format("{}", last_mod);
14811 }
14812
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14813
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 fs::path backup_path = fs::path("backups") / backup_fname;
14814
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!fs::exists(backup_path))
14815 {
14816
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 fs::create_directories(fs::path("backups"));
14817
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (fs::copy_file(filename, backup_path))
14818 {
14819
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
5 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14820 5 }
14821 else
14822 {
14823 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14824 }
14825 5 }
14826 5 }
14827
14828 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14829 9 fake_pack_writing = false;
14830
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14831 {
14832 box_out("-- Error saving quest file! --");
14833 box_end(true);
14834 }
14835 9 else box_end(false);
14836 9 return ret;
14837 }
14838
14839 9 int32_t save_quest(const char *filename, bool timed_save)
14840 {
14841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14842
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14843 char ext1[5];
14844 9 ext1[0]=0;
14845
14846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14847 {
14848 sprintf(ext1, "qt");
14849 }
14850 else
14851 {
14852 9 sprintf(ext1, "qb");
14853 }
14854
14855
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14856 {
14857 char backupname[2048];
14858 char backupname2[2048];
14859 char ext[12];
14860
14861 for(int32_t i=retention-1; i>0; --i)
14862 {
14863 sprintf(ext, "%s%d", ext1, i-1);
14864 replace_extension(backupname, filepath, ext, 2047);
14865
14866 if(exists(backupname))
14867 {
14868 sprintf(ext, "%s%d", ext1, i);
14869 replace_extension(backupname2, filepath, ext, 2047);
14870
14871 if(exists(backupname2))
14872 {
14873 remove(backupname2);
14874 }
14875
14876 rename(backupname, backupname2);
14877 }
14878 }
14879
14880 //don't do this if we're not saving to the same name -DD
14881 if(!timed_save && !strcmp(filepath, filename))
14882 {
14883 sprintf(ext, "%s%d", ext1, 0);
14884 replace_extension(backupname, filepath, ext, 2047);
14885 rename(filepath, backupname);
14886 }
14887 }
14888
14889 int32_t ret;
14890 9 ret = save_unencoded_quest(filename, compress, filename);
14891
14892 9 return ret;
14893 }
14894
14895 1 void center_zq_class_dialogs()
14896 {
14897 1 jwin_center_dialog(pwd_dlg);
14898 1 }
14899
14900 void zmap::prv_secrets(bool high16only)
14901 {
14902 mapscr *s = &prvscr;
14903 mapscr *t = prvlayers;
14904 int32_t ft=0;
14905
14906 for(int32_t i=0; i<176; i++)
14907 {
14908 if(!high16only)
14909 {
14910 for(int32_t j=-1; j<6; j++)
14911 {
14912 int32_t newflag = -1;
14913
14914 for(int32_t iter=0; iter<2; ++iter)
14915 {
14916 if(!t[j].valid)
14917 continue;
14918
14919 int32_t checkflag=combobuf[t[j].data[i]].flag;
14920
14921 if(iter==1)
14922 {
14923 checkflag=t[j].sflag[i];
14924 }
14925
14926 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14927 if (ft != -1)
14928 {
14929 if(j==-1)
14930 {
14931 s->data[i] = s->secretcombo[ft];
14932 s->cset[i] = s->secretcset[ft];
14933 newflag = s->secretflag[ft];
14934 }
14935 else
14936 {
14937 t[j].data[i] = t[j].secretcombo[ft];
14938 t[j].cset[i] = t[j].secretcset[ft];
14939 newflag = t[j].secretflag[ft];
14940 }
14941 }
14942 }
14943
14944 if(newflag >-1)
14945 {
14946 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14947 }
14948 }
14949 }
14950
14951 //if(true)
14952 //{
14953 int32_t newflag = -1;
14954
14955 for(int32_t iter=0; iter<2; ++iter)
14956 {
14957 int32_t checkflag=combobuf[s->data[i]].flag;
14958
14959 if(iter==1)
14960 {
14961 checkflag=s->sflag[i];
14962 }
14963
14964 if((checkflag > 15)&&(checkflag < 32))
14965 {
14966 s->data[i] = s->secretcombo[(checkflag)-16+4];
14967 s->cset[i] = s->secretcset[(checkflag)-16+4];
14968 newflag = s->secretflag[(checkflag)-16+4];
14969 // putit = true;
14970 }
14971 }
14972
14973 if(newflag >-1) s->sflag[i] = newflag;
14974
14975 for(int32_t j=0; j<6; j++)
14976 {
14977 if(!t[j].valid) continue;
14978
14979 int32_t newflag2 = -1;
14980
14981 for(int32_t iter=0; iter<2; ++iter)
14982 {
14983 int32_t checkflag=combobuf[t[j].data[i]].flag;
14984
14985 if(iter==1)
14986 {
14987 checkflag=t[j].sflag[i];
14988 }
14989
14990 if((checkflag > 15)&&(checkflag < 32))
14991 {
14992 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14993 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14994 newflag2 = t[j].secretflag[(checkflag)-16+4];
14995 }
14996 }
14997
14998 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14999 }
15000 }
15001
15002 //FFCs
15003 word num_ffcs = s->numFFC();
15004 for(word i=0; i<num_ffcs; ++i)
15005 {
15006 if(!high16only)
15007 {
15008 for(int32_t iter=0; iter<1; ++iter)
15009 {
15010 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15011
15012 if(iter==1)
15013 {
15014 checkflag=s->sflag[i];
15015 }
15016
15017 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15018 if (ft != -1)
15019 {
15020 s->ffcs[i].data = s->secretcombo[ft];
15021 s->ffcs[i].cset = s->secretcset[ft];
15022 }
15023 }
15024 }
15025
15026 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15027 {
15028 for(int32_t iter=0; iter<1; ++iter)
15029 {
15030 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15031
15032 if(iter==1)
15033 {
15034 // FFCs can't have flags! Yet...
15035 }
15036
15037 if((checkflag > 15)&&(checkflag < 32))
15038 {
15039 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15040 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15041 }
15042 }
15043 }
15044 }
15045 }
15046